Skip to content
Search

Locate

lastmod 2018-08-17created 2015-07-313 edits

A Unix/Linux command that searches file names at high speed.

locate uses a database to search all paths and displays the file names that match the Pattern. The database is rebuilt periodically (usually weekly or daily). The database contains every file name accessible to all users. The Pattern can use shell wildcards (*, ?, \, [" "]). In that case, the wildcards must be escaped so the shell does not interpret them. Prefixing any character with a Backslash("\") removes whatever special meaning that character has. No character, including Slash("/"), has special meaning.

Also, when a pattern without wildcards is given, e.g. "foo", locate interprets it as "foo".

For historical reasons, older versions of locate could only handle character codes 32 to 127. The current method can handle any character code except newline('\n') and null('\0').

Usage

Usage is as follows.

$ locate [ -Scims] [ -l limit] [ -d database] pattern ...

To update manually, run the #updatedb command.

updatedb

(This page can also be reached via updatedb)

The updatedb utility updates the database used by locate. It is normally run once a week by a script.

ArchLinux install

In other distributions, locate and updatedb are in the findutils package, but they are no longer in the Arch package. To use them, install the mlocate package. The mlocate package improves on the older tools but is used the same way. Before using locate, you need to create the database. To do so, simply run the updatedb command with root privileges.

Keeping the database up to date

When mlocate is installed, a /etc/cron.daily (run daily by cron) script that updates the database is installed automatically. You can also run updatedb manually at any time.

To save time, updatedb can be configured to ignore certain file systems and paths by editing /etc/updatedb.conf. man updatedb.conf explains the meaning of this file. Among the paths ignored in the default configuration file (specified in the "PRUNEPATHS" string) are /media and /mnt. As a result, locate may not find files on external devices.

Favorite site