Friday, November 14, 2008

locate - Unix desktop search

If you are searching for a desktop search system on unix systems with command line interface, locate is the command. locate indexes all the data on your system so that it can answer your queries quickly. Roughly its equivalent to doing a grep on all the files in your system. Problem with grep is that, it might take hours together to findout files containing a specific pattern. locate does it in less than a second.

$ locate pattern ## find files on the system containing this pattern

locate keeps an indexed DB of all the files on your system. It needs to be updated as new files gets added or files gets removed or updated. To update this DB, you can use following commands. On linux you can use -

$ sudo updatedb

On freebsd you can use -

$ sudo /usr/libexec/locate.updatedb

More useful thing to do would be to add this command to your crontab so it updates DB at regular frequency automatically.

$ crontab -e

0 0 * * sun # update locate db, every sunday midnight


locate is very helpful to find files quickly when you rember only some approximate content of it. find and grep can give the same results. But its very time consuming.

No comments: