Name
locate — stdin stdout - file -- opt --help --version
Synopsis
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 stringlocate 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/myindexIndexing options for updatedb
|
|
Create index from the root directory downward. |
|
|
Create index from
|
|
|
Turn security off (0) or on (1). The default is 1. |
|
|
Exclude ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access