The plocate Command as a Faster Alternative to locate in Linux

The plocate Command as a Faster Alternative to locate in Linux

The plocate command finds all files on the system matching the given pattern. It is a locate based on posting lists, providing much faster searches on a 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 tiny list instead of linearly scanning through every entry.

Named for the posting lists that inspired it, the plocate command aims 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 offers this benchmark on the tool’s homepage in which plocate can find two files out of 27 million in just a few milliseconds:

plocate command

The tool quickly gained popularity. For example, Fedora 36 plans 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 22.04:

sudo apt install plocate

Arch Linux and its 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 the plocate command to look for a file is 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 update the database regularly. 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 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 down from the root.

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

Leave a Reply

Your email address will not be published.