locate | |
---|---|
Initial release | 1982 |
Operating system | Unix and Unix-like |
Type | Command |
locate
is a Unix utility which serves to find files on filesystems. It searches through a prebuilt database of files generated by the updatedb
command or by a daemon and compressed using incremental encoding. It operates significantly faster than find
, but requires regular updating of the database. This sacrifices overall efficiency (because of the regular interrogation of filesystems even when no user needs information) and absolute accuracy (since the database does not update in real time) for significant speed improvements, particularly on very large filesystems.
locate
locate
was first created in 1982. [1] The BSD and GNU Findutils versions derive from the original implementation. [2] A locate
command is also included in MacOS.
mlocate
(Merging Locate) and the earlier slocate
(Secure Locate) use a restricted-access database, only showing filenames accessible to the user. [3] [4]
GNU findutils' locate
database can be built either in the traditional way (as a world-readable database of files accessible by everybody) or in the manner of slocate
, in which the database contains more files, but the output is filtered to show the user only the names of files they have access to. [5]
plocate
uses posting lists. Like mlocate
and slocate
, it only shows files if find
would list it. [6] Compared to mlocate
, it is much faster, and its index is smaller. [7] [8]
find
and locate
When find
searches a large file system, it performs many system calls and reads from many locations on the storage media. This is often quite slow. The locate
command, by comparison, generally reads a compressed database and lists the matching files. So locate
generally performs much less I/O per match. However, find
can operate faster if you only want to search a small directory (not the whole file system).
GNU locate and its associated utilities were originally written by James Woods, with enhancements by David MacKenzie.
...faster and does not trash the system caches as much...attempts to be compatible to GNU locate, when it does not conflict with slocate compatibility.
...will also check file permissions and ownership so that users will not see files they do not have access to.
The 'slocate' database format is very similar to 'LOCATE02' and is also supported (in both updatedb and locate).
Variants: