
The locate command is very useful if you’re looking to track down every instance of a file, filetype, app, extension, things hidden deep in system folders, or just about anything else that Spotlight can’t manage. It’s extraordinarily useful for troubleshooting and even more mundane tasks like completely uninstalling Mac apps.
In order to use locate, you need to build the locate database, which also enables a few other helpful commands including whatis, find, and the manual keyword search ‘man -k’. OS X 10.7 is better at building this for you, but if you don’t have locate enabled yet all that is required is typing this command into the Terminal:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
This is told to you directly by OS X the first time you attempt to run locate or any of the commands dependent on the database:
$ locate python
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.
How long it takes to generate the database varies, but the larger your hard disk the longer it’ll be. You can watch the progress indirectly through Activity Monitor, where the “find” process will be running at around 15-30% CPU use until the locate database is generated.

Alternatively you can also run the following command and build the database:
sudo /usr/libexec/locate.updatedb
As with many terminal commands, locate accepts wildcards and regular expressions, helping you narrow down advanced searches. For example, you could find every possible file with a .jpg extension by using:
locate *.jpg
Some jpg files will inevitably have an uppercase extension though, and you can tell locate to ignore case sensitivity with -i:
locate -i *.jpg
There are plenty of other options you can work with, refer to ‘man locate’ for more info.
Don’t forget to check out more OS X command line tips too.