To update the file database, you have to run the updatedb command as the root user:
root@ubuntu-linux:~# updatedb
The updatedb command will not display any output.
Now, let’s say we forgot the location of the file facts.txt, and we don’t remember where it is; in this case, you can run the locate command followed by the filename:
root@ubuntu-linux:~# locate facts.txt
/home/elliot/facts.txt
/var/facts.txt
BOOM! It displayed the location of the file facts.txt.
Now I will show you what will happen if you search for a newly created file without updating the file database.
Create an empty file named ghost.txt in the /home directory:
root@ubuntu-linux:/# touch /home/ghost.txt
Now try searching for the file ghost.txt:
root@ubuntu-linux:/# locate ghost.txt
root@ubuntu-linux:/#
The locate command couldn’t find it! Why is that?........ That’s because you created a new file, and the file database doesn’t know about it yet. You have to run...