my-server
← Wiki

Locate (Unix)

<code>locate</code> is a Unix utility which serves to find files on filesystems. It searches through a prebuilt database of files generated by the <code>updatedb</code> command or by a daemon and compressed using incremental encoding. It operates significantly faster than <code>find</code>, 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.

Implementations of <code>locate</code>

<code>locate</code> was first created in 1982. The BSD and GNU Findutils versions derive from the original implementation. A <code>locate</code> command is also included in MacOS.

<code>mlocate</code> (Merging Locate) and the earlier <code>slocate</code> (Secure Locate) use a restricted-access database, only showing filenames accessible to the user.

GNU findutils' <code>locate</code> database can be built either in the traditional way (as a world-readable database of files accessible by everybody) or in the manner of <code>slocate</code>, 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.

<code>plocate</code> uses posting lists. Like <code>mlocate</code> and <code>slocate</code>, it only shows files if <code>find</code> would list it. Compared to <code>mlocate</code>, it is much faster, and its index is smaller.

Performance differences between <code>find</code> and <code>locate</code>

When <code>find</code> 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 <code>locate</code> command, by comparison, generally reads a compressed database and lists the matching files. So <code>locate</code> generally performs much less I/O per match. However, <code>find</code> can operate faster if you only want to search a small directory (not the whole file system).

See also

  • mdfind related command in MacOS

References

External links

Variants:

  • plocate - Variant faster than mlocate, with a smaller index.
  • rlocate - Variant using kernel module and daemon for continuous updates.
  • KwickFind - KDE GUI frontend for locate
  • Locate32 for Windows - GPL'ed graphical Windows variant