Locate (Unix)

locate

Initial release| 1982; 43 years ago (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.

## Implementations of `locate`

[edit]

`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]

## Performance differences between `find` and `locate`

[edit]

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

[edit]

* mdfind related command in MacOS

## References

[edit]

1. ^ Woods, James A. (1983-01-15). "Finding Files Fast". ;login:. Vol. 8, no. 1\. Usenix. pp. 8–10. Retrieved 2016-03-27.
2. ^ "Finding Files". GNU. Free Software Foundation. 2012-11-17. Retrieved 2016-03-27. "GNU locate and its associated utilities were originally written by James Woods, with enhancements by David MacKenzie."
3. ^ Miloslav Trmač (2005). "mlocate". Archived from the original on 2006-04-11. Retrieved 2016-03-27. "...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."
4. ^ Kevin Lindsay (1999). "Secure Locate". Archived from the original on 2005-05-07. Retrieved 2016-03-27. "...will also check file permissions and ownership so that users will not see files they do not have access to."
5. ^ James Youngman. "Database Formats". Archived from the original on 2024-05-30. Retrieved 2025-05-10. "The 'slocate' database format is very similar to 'LOCATE02' and is also supported (in both updatedb and locate)."
6. ^ Gunderson, Steinar. "plocate, a much faster locate". plocate.sesse.net. Retrieved 23 February 2023.
7. ^ Gunderson, Steinar. "plocate(1)". man.archlinux.org. Arch manual pages. Retrieved 23 February 2023.
8. ^ "plocate". Kali Linux. Kali Linux Tools. Retrieved 23 February 2023.

## External links

[edit]

* GNU Findutils
* mlocate
* `locate(1)` – FreeBSD General Commands Manual
* `locate(1)` – OpenBSD General Commands Manual
* `locate(1)` – Linux User Manual – User Commands

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

* v
* t
* e

Unix command-line interface programs and shell builtins

File system|

* cat
* chattr
* chmod
* chown
* chgrp
* cksum
* cmp
* cp
* dd
* du
* df
* file
* fuser
* ln
* ls
* mkdir
* mv
* pax
* pwd
* rm
* rmdir
* split
* tee
* touch
* type
* umask

Processes|

* at
* bg
* crontab
* fg
* kill
* nice
* ps
* time

User environment|

* env
* exit
* logname
* mesg
* talk
* tput
* uname
* who
* write

Text processing|

* awk
* basename
* comm
* csplit
* cut
* diff
* dirname
* ed
* ex
* fold
* head
* iconv
* join
* m4
* more
* nl
* paste
* patch
* printf
* read
* sed
* sort
* strings
* tail
* tr
* troff
* uniq
* vi
* wc
* xargs

Shell builtins|

* alias
* cd
* echo
* test
* unset
* wait

Searching|

* find
* grep

Documentation|

* man

Software development|

* ar
* ctags
* lex
* make
* nm
* strip
* yacc

Miscellaneous|

* bc
* cal
* expr
* lp
* od
* sleep
* true and false

* Categories
* Standard Unix programs
* Unix SUS2008 utilities
* List

This Unix-related article is a stub. You can help Wikipedia by expanding it.

|

* v
* t
* e

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template