Glossary

locate

locate finds files by name by consulting a database prebuilt by updatedb, typically updated by a nightly cron job. Because it does not touch the filesystem at query time, locate is essentially instantaneous even on systems with millions of files. The trade-off is staleness: files created or deleted since the last database update are invisible to locate.

locate firefox                      # any path containing 'firefox'
locate -i README                    # case insensitive
locate -b '\\conf'                   # basename only
locate -r '\\.pdf$'                  # regex
sudo updatedb                       # refresh the database manually

Two implementations exist: mlocate (merged locate, the Debian/Ubuntu default for years) and plocate (faster posting-list based, now becoming the default). Both respect /etc/updatedb.conf, which lists paths to exclude (typically /media, /mnt, /tmp).

For quick "where did I put that file" questions, locate is hard to beat. For finding files by any criterion other than name, or for guaranteed-fresh results, use find. They are complementary tools, and serious Linux users keep both close at hand.

Related terms: find

Discussed in:

Also defined in: Textbook of Linux