Well guys, here one of the most powerful commands along with find to look for files. In this howto we are gonna deal with locate. With locate we can find files instantly. Just typing
and within a second give us the results.
But what if we want files ending with the extension .pdf. Then
and what if we want those pdf files within our /home/username
locate ‘*.pdf’ | grep username
What happens if this is a long list, and we want a pause to see these files
locate ‘*.pdf’ | grep username | more
locate ‘*.pdf’ | grep username | less
Both of them do the trick.
So, the question, why locate is so fast?
Because it has a database of all the files stored in our computer. So, if we just saved a file
, locate will not find it, unless we update the database by doing
But, it is not necessary, Ubuntu has a cron job for this in /etc/cron.daily/slocate
We can specify/create additional databases with locate -U, so locate -U /home/username would create a database for those files stored in our /home/username directory. But to be sincere, it is not necessary when we have the power of pipes.