HOWTO: Locate, looking for files the fast way

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

locate nameofthefile

and within a second give us the results.

But what if we want files ending with the extension .pdf. Then

locate ‘*.pdf’

and what if we want those pdf files within our /home/username

Then

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

sudo updatedb

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.

Advertisements

About jordilin

I'm a Senior Software Engineer with an MSc in Telecommunications Engineering. I've got a range of interests including Linux, a very powerful and limitless operating system, travelling, gastronomy and technology.
This entry was posted in HOWTOs, Ubuntu Linux. Bookmark the permalink.

One Response to HOWTO: Locate, looking for files the fast way

  1. Pingback: Wedding hair

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s