locate Is a Unix tool for finding files by name on the file system. It uses a pre-built database of generated files (using
find , But it needs to update the database to find newly added files.
locate Created in 1982, the BSD and GNU Findutils versions are derived from the original implementation.
position Is newer (the first stable version is less than a year ago), much faster
locate . It is based on the release list and provides faster search on a smaller index.
Command line tools are alternatives
mlocate (Merge location; access restricted database, only display user-accessible file names) Almost all aspects, including reuse
mlocate Database (use plocate to create your own index
plocate-build It reads by
updatedb ), and it’s fast on both SSD and HDD.
plocate works by creating an inverted index on triples (a combination of three bytes) in the search string, which allows it to quickly narrow the candidate set to a very small list instead of linearly scanning each entry . It uses io_uring (if available) (Linux 5.1+) to perform almost all I/O asynchronously, which reduces the impact of seek latency on systems without SSD.
You may also like: How to use find to find files that have been modified in the last N days or minutes
In order to show how fast plocate is compared to mlocate, the plocate developers showed this benchmark on the tool’s homepage, where plocate was able to find 2 of the 27 million files within a few milliseconds:
mlocate , plocate Only display all files matching the search query when the user running the command is visible, skipping all restricted files.
How to install and use plocate
plocate is available in the official repositories of some Linux distributions, including Arch Linux / Manjaro and Debian (Bullseye and newer, and Buster backports)/ Ubuntu (21.04 and newer). You can install it using the following methods:
- Arch Linux / Manjaro:
sudo pacman -S plocate
- Debian (Bullseye and newer, and Buster backport) / Ubuntu (21.04 and newer):
plocate find files command linesudo apt install plocate
To build it on other Linux distributions, you need a C++17 compiler, Zstd (development header files), and Meson.In my testing of Fedora, I must also install
libatomic To build the program.Or, you also need
liburing And a kernel support
io_uring (Linux 5.1 or newer) for best performance, especially if you are not using SSD. Another optional dependency is systemd, which can be used to run the built-in plocate database update timer.
Install plocate build dependencies on Fedora (including optional
liburing ), use:
sudo dnf install libzstd-devel liburing-devel libatomic gcc-c++ meson
Or build it on, for example, Ubuntu 20.04 (note that Ubuntu 20.04 does not
liburing In its repository, if you are using a normal hard drive, then plocate will not use all its features), you will need these dependencies:
sudo apt install libzstd-dev meson build-essential
Once the build dependencies are installed, download And extract plocate, then use the terminal to navigate to its folder. Now you can continue to build and install plocate on your system:
sudo groupadd --system plocate
sudo ninja installsudo systemctl enable plocate-updatedb.timer
Now you can start using plocate. Before using it for the first time, use the following command to create its database (file index):
updatedb , It will scan the entire file system, which may take a while. Subsequent runs should be much faster.
plocate Like you would use
locate . Use plocate to search for files:
MY_FILE.EXT And the file you are looking for.
For more options such as ignoring case, regular expression search, etc., please refer to the tool’s help and man pages.
You may like: How to use find to delete files older than or later than N days (additional example)