Forget About the locate Command, plocate is a Much Faster Alternative

The plocate command is a drop-in replacement for mlocate in nearly all aspects.

plocate command

plocate finds all files on the system matching the given pattern. It is a locate based on posting lists, giving much faster searches on a much smaller index.

When you need to search for some files in Linux, you might typically use find or locate commands. So, now you have a new alternative called plocate.

plocate works by creating an inverted index over trigrams (combinations of three bytes) in the search strings, which allows it to rapidly narrow down the set of candidates to a very small list, instead of linearly scanning through every entry.

Named for the posting lists that inspired it, plocate was written to be a drop-in replacement for mlocate. While it can still use updatedb to create its database, plocate can also use the plocate-build utility to create an index.

Unlike mlocate, when multiple strings are searched, plocate returns only the files that match all the search strings, rather than any file that matches even one string.

To show how fast the plocate command is, the developer shows this benchmark on the tool’s homepage in which plocate is able to find 2 files out of 27 million in just a few milliseconds:

plocate command

The tool quickly gained popularity. For example, Fedora 36 is planning to use plocate as its new provider of the locate command for finding files on file-systems.

Install

Debian 11 Bullseye and newer, Debian 10 Buster backports, Ubuntu 21.04, 21.10 and newer:

sudo apt install plocate

Arch Linux and it derivatives:

sudo pacman -S plocate

Fedora:

sudo dnf install plocate

How to Use plocate

Now you can start using plocate. First you need to create its database (file index):

sudo updatedb

Firing plocate command to look for a file is pretty easy and straightforward. For example to search for a file named backup.py you would type:

plocate backup.py
plocate find files

If there are files you cannot find, there are two likely culprits:

1. First, check that the database has been updated recently. Most users will want to use plocate’s updatedb.

There is a service and a timer to regularly update the database. You can enable it and it will automatically trigger the service with:

sudo systemctl enable plocate-updatedb.timer
sudo systemctl start plocate-updatedb.timer

2. The other reason why a file isn’t shown, is typically permissions. Check if you can find the files as root and if you can, the problem is most likely that you don’t have access rights to the directory all the way down from the root.

For more about plocate command in Linux, consult its manual page

Leave a Reply

Your email address will not be published.

Latest from Linux Knowledge