locate — stdin stdout - file -- opt --help --version
locate [options
]
The locate
command, with
its partner updatedb
, creates an
index (database) of file locations that is quickly
searchable.[13] If you plan to locate many files over time in a
directory hierarchy that doesn’t change much, locate
is a good choice. For locating a
single file or performing more complex processing of found files,
use find
.
Some distros automatically index the entire filesystem on a
regular basis (e.g., once a day), so you can simply run locate
and it will work. But if you ever
need to create an index yourself of a directory and all its
subdirectories (say, storing it in /tmp/myindex), run:
$ updatedb -l0 -U directory
-o /tmp/myindex
(Note that -l0
is a
lowercase L
followed by a zero,
not the number 10.) Then to search for a string in the index:
$ locate -d /tmp/myindex string
locate
has an interesting,
optional security feature. You can create an index that, when
searched, will display only files that the user is permitted to see.
So if the superuser created an index of a protected directory, a
non-superuser could search it but not see the protected files. This
is done by omitting the -l0
option to updatedb
and running it
as root:
# updatedb -U directory
-o /tmp/myindex
|
Create index from the root directory downward. |
|
Create index from
|
|
Turn security off (0) or on (1). The default is 1. |
|
Exclude one or more directories from the index. Separate their paths by commas. |
|
Write the index to
file |
[13] Our locate
command
comes from a package called “mlocate.” Some systems have an
older package called “slocate” with slightly different usage. If
you have slocate, simply type slocate
instead of updatedb
in our examples.
18.191.174.168