Locate (Unix)

{{lowercase title}}

{{Infobox software

| name = locate

| logo =

| screenshot =

| screenshot size =

| caption =

| author =

| developer =

| released = {{Start date and age|1982}}

| latest release version =

| latest release date =

| operating system = Unix and Unix-like

| genre = Command

| license =

| website =

}}

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.

Implementations of <code>locate</code>

locate was first created in 1982.{{cite magazine|last=Woods|first=James A.|date=1983-01-15|title=Finding Files Fast|url=https://archive.org/details/login-feb83/page/n7/mode/2up?view=theater|magazine=;login:|volume=8|issue=1|pages=8–10|publisher=Usenix|access-date=2016-03-27}} The BSD and GNU Findutils versions derive from the original implementation.{{cite web|url=https://www.gnu.org/software/findutils/manual/html_node/find_html/Introduction.html#Introduction|title=Finding Files|date=2012-11-17|website=GNU|publisher=Free Software Foundation|access-date=2016-03-27|quote=GNU locate and its associated utilities were originally written by James Woods, with enhancements by David MacKenzie.}} 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.{{cite web|url=http://carolina.mff.cuni.cz/~trmac/blog/mlocate/|archive-url=https://web.archive.org/web/20060411074142/http://carolina.mff.cuni.cz/~trmac/blog/mlocate/|archive-date=2006-04-11|title=mlocate|date=2005|author=Miloslav Trmač|access-date=2016-03-27|quote=...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.|url-status=dead}}{{cite web|url=http://www.geekreview.org/slocate/|archive-url=https://web.archive.org/web/20050507092723/http://www.geekreview.org/slocate/|archive-date=2005-05-07|title=Secure Locate|date=1999|author=Kevin Lindsay|access-date=2016-03-27|quote=...will also check file permissions and ownership so that users will not see files they do not have access to.|url-status=dead}}

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.{{cite web|url=https://www.gnu.org/software/findutils/manual/html_node/find_html/Database-Formats.html|archive-url=https://web.archive.org/web/20240530125454/https://www.gnu.org/software/findutils/manual/html_node/find_html/Database-Formats.html|archive-date=2024-05-30|title=Database Formats|author=James Youngman|access-date=2025-05-10|quote=The ‘slocate’ database format is very similar to ‘LOCATE02’ and is also supported (in both updatedb and locate).}}

plocate uses posting lists. Like mlocate and slocate, it only shows files if find would list it.{{cite web |last1=Gunderson |first1=Steinar |title=plocate, a much faster locate |url=https://plocate.sesse.net |website=plocate.sesse.net |access-date=23 February 2023 |language=en}} Compared to mlocate, it is much faster, and its index is smaller.{{cite web |last1=Gunderson |first1=Steinar |title=plocate(1)|url=https://man.archlinux.org/man/community/plocate/plocate.1.en |website=man.archlinux.org |publisher=Arch manual pages |access-date=23 February 2023}}{{cite web |title=plocate |url=https://www.kali.org/tools/plocate/ |website=Kali Linux |publisher=Kali Linux Tools |access-date=23 February 2023 |language=English}}

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

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).

See also

  • mdfind related command in MacOS

References

{{Reflist}}