Wednesday, May 8, 2013

Newbie help: The "locate" command

Some *nixes, including Centos and Red Hat have an indexed finder utility called locate.  It's a very limited tool, but when you know what you're looking for, it can be the quickest way to find a file.

Basic usage:
locate [-i insensitive, -w wholename] a-filename-substring

It will generally return too much info, so grep for other known substrings to pare down the results.

Example:  I know exactly what file I want, but where did I put it?
$locate iCanHasPortlet.war
/app/liferay/iCanHasPortlet.war

Example:  I only know bits of a ridiculously long filename, what was it?
Mac:~ kexline$ locate -i license | grep -i prod | grep -i acme
/Users/kexline/Documents/liferay/licenses/license-production-production-5.6sp3-acmecomputercompany-main.xml

If locate doesn't cough up the goods, then your index is probably older than the desired file.  (Locate is not useful for new files; but then again, if something is very new you should know what or where it is.)  On RH/Centos, become root, run updatedb & , and get some coffee. 

No comments: