To search for files by name without having to actually scan the
directories on the disk (which can be slow), you can use the
locate
program. For each shell pattern you give it,
locate
searches one or more databases of file names and displays
the file names that contain the pattern. See Shell Pattern Matching,
for details about shell patterns.
If a pattern is a plain string—it contains no
metacharacters—locate
displays all file names in the database
that contain that string. If a pattern contains
metacharacters, locate
only displays file names that match the
pattern exactly. As a result, patterns that contain metacharacters
should usually begin with a *, and will most often end with one
as well. The exceptions are patterns that are intended to explicitly
match the beginning or end of a file name.
If you only want locate
to match against the last component of
the filenames (the “base name” of the files) you can use the
--basename option. The opposite behaviour is the default, but
can be selected explicitly by using the option --wholename.
The command
locate pattern
is almost equivalent to
find directories -name pattern
where directories are the directories for which the file name
databases contain information. The differences are that the
locate
information might be out of date, and that locate
handles wildcards in the pattern slightly differently than find
(see Shell Pattern Matching).
The file name databases contain lists of files that were on the system when the databases were last updated. The system administrator can choose the file name of the default database, the frequency with which the databases are updated, and the directories for which they contain entries.
Here is how to select which file name databases locate
searches.
The default is system-dependent.
--database=
path-d
pathLOCATE_PATH
to set the list of database files to search. The
option overrides the environment variable if both are used.