Locate (Unix)
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 and absolute accuracy for significant speed improvements, particularly on very large filesystems.Implementations of locate
locate was first created in 1982. The BSD and GNU Findutils versions derive from the original implementation. A locate command is also included in MacOS.mlocate and the earlier slocate use a restricted-access database, only showing filenames accessible to the user.GNU findutils'
locate database can be built either in the traditional way 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.plocate uses posting lists. Like mlocate and slocate, it only shows files if find would list it. Compared to mlocate, it is much faster, and its index is smaller.Performance differences between 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.