{{Short description|Utility to find files on Unix systems}} {{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 = }} '''<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.<ref>{{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}}</ref> The BSD and GNU Findutils versions derive from the original implementation.<ref>{{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.}}</ref> 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.<ref>{{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}}</ref><ref>{{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}}</ref>
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.<ref>{{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).}}</ref>
<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.<ref>{{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}}</ref> Compared to <code>mlocate</code>, it is much faster, and its index is smaller.<ref>{{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}}</ref><ref>{{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}}</ref>
== 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 == {{Reflist}}
== External links == * [https://www.gnu.org/software/findutils/findutils.html GNU Findutils] * [https://pagure.io/mlocate mlocate] * {{man|1|locate|FreeBSD}} * {{man|1|locate|OpenBSD}} * {{man|1|locate|Linux}}
Variants: * [https://plocate.sesse.net/ plocate] - Variant faster than mlocate, with a smaller index. * [https://rlocate.sourceforge.net/ rlocate] - Variant using kernel module and daemon for continuous updates. * [https://web.archive.org/web/20151222075946/http://kde-apps.org/content/show.php/KwickFind+(Locate+GUI+Frontend)?content=54817 KwickFind] - KDE GUI frontend for locate * Locate32 for Windows - GPL'ed graphical Windows variant
{{Unix commands}}
Category:GNU Project software Category:Unix file system-related software Category:Information retrieval systems
{{Unix-stub}}