A modern search tool
Command Line – plocate
As the latest successor to locate, plocate produces some of the quickest search results possible on any system.
Real estate agents sometimes say that the key to success is location, location, location. This saying might almost summarize the history of the locate
command [1] and its various successors, particularly mlocate
[2] and plocate
[3]. As a replacement for find
, all three commands use a database solution to reduce search time. While all three share many of the same options, plocate
is widely considered the most efficient choice.
Slightly different versions of locate
are available in the BSD and GNU findutils, but you can also find locate
, mlocate
, and plocate
as separate commands. Because the number of choices can be confusing, a history seems in order. First released in 1982, locate
uses a database that can be read by any user. If regular expressions are not used, it displays every instance of the string entered on the system, which is inconvenient if the string is common. However, locate
's most serious limitation is that the database has to be updated manually. Largely because of these problems – especially the need for manual updates – locate
was succeeded briefly by slocate
(secure locate) [4] until replaced in 2006 by mlocate
(merging locate). Both slocate
and mlocate
are an improvement over locate
in that they contain the utility updatedb
[5] to update databases, speeding up the process by only searching for files and directories where the ctime
has changed. Also, both slocate
and mlocate
show only the files that the current user has access to, thereby improving security, and they allow regular expressions to be used without a specific option. Written by Miloslav Trmac while he participated in the Google Summer of Code, mlocate
became the preferred version until 2020, although it seems to have gone through periods of being unmaintained.
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 [6] to create an index when a root user is logged in. 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. Another difference from mlocate
: plocate
is compatible with systemd and SELinux. Instead of scanning every entry one at a time, plocate
scans trigrams (i.e., combinations of three bytes at a time) to increase search speeds. Although specifically designed for solid state drives (SSDs), on older hard drives, plocate
can gain further speed by using the io_uring
Asynchronous I/O (AIO) framework introduced in the Linux 5.1 kernel in March 2019 [7]. As its main limitation, plocate
's benefits may be lost when searching for strings shorter than three bytes, for non-UTF-8 file names, or for regular expressions with numerous hits. Usually, its enhancements mean that plocate
can find two files out of 27 million in .008 milliseconds, while mlocate
takes 20.118 milliseconds for the same operation [8]. Even though locate
and mlocate
are still available, in most circumstances, plocate
should be the preferred variant.
Setting Up plocate
You can find plocate
in the official repositories of Arch Linux, Manjaro, Debian (Buster backports and Bullseye releases), and Ubuntu. On other distributions, you can build plocate
with zstd and libtomic
using a C++ compiler. Whichever way you install it, before you use plocate
, you must run updatedb
to create at least one database at /var/lib/mlocate/mlocate.db
(Figure 1). This process may take a while to run the first time if the system is not on an SSD drive and does not run at least a Linux 5.1 kernel. Otherwise, on a 2TB system, the database is created in a matter of a few seconds. To specify a non-default location for the database, use: --database-root FILE
. You can add --database-root FILE
(-U FILE
) to specify a non-default location for the database, and --require-visibility 0
(-l 0
) to make the entire content of the database visible to ordinary users. Adding --verbose
(-v
) will display the files and directories being added to the database onscreen, which has the advantage of letting you know when the database creation is complete. Alternatively, you can create the database using plocate-build
, even creating a plain text database if you choose. Either way, you can check that plocate
is ready to use by doing a simple search (Figure 2).
Of note, mlocate
includes a few options that plocate
lacks. For example, mlocate
includes --statistics
(-S
) as well as --stdio
(-s
), a C function for interacting with different physical devices, for compatibility with the BSD and GNU versions of locate
. What remains in plocate
are a dozen basic functions, which are more than enough for almost all operations.
On networks, plocate
can be modified by adding multiple databases with --database PATH
(-d PATH
). Multiple databases can be specified one per option or in a single option with the names of databases separated by a colon (:). Note that versions of Ubuntu before 21.04 may not have these options and may not mention them in their man pages. Two other options signal that a search string should be treated as containing regular expressions: --regexp
(-r
) signals the presence of standard regular expressions and --regex
signals that extended regular expressions are used. Because regular expressions can return a large number of results, these options can noticeably slow a search. Without one of these options, common symbols in regular expressions such as *, ?, or ! are treated as regular text.
Other options modify a search's results. With --ignore-case
(-i
), plocate
's default case sensitivity is overwritten, so that lowercase and uppercase letters are treated as the same, except in the case of some Unicode case rules, such as a German ß being the same as ss. Moreover, like regular expressions, ignoring letter case can slow the search by producing a larger number of results, but search speed can be increased. For instance, on one hand --limit NUMBER
(-l NUMBER
) stops a search after the designated number of hits, and --count
(-c
) merely shows the number of instances. On the other hand, --basename
(-b
), which searches only for file names without their extensions, increases search speed only minimally at best by omitting directories from the search.
A Command for Modern Times
With the recent release of plocate
, the locate
family of commands seems set for the next few years. While plocate
has a few limitations, it uses the latest technology and is adopted to modern computing practices. For example, with the current hardware speeds, it no longer makes sense to set whether to follow symbolic links – following them by default can be done with no noticeable effects.
Even more important, the rise of Linux on the desktop has increased the demand for simplicity. In the past, the find
command, with its arcane distinctions, was sufficient because users could be assumed to have the expertise and the patience to wade through the obscurities of its man page. Today, though, with lessveteran users, simplicity and efficiency are expected as the norms. In the case of system searches, these expectations have resulted in plocate
, one of the increasing number of rewrites of classic Linux commands that users have lived with for so long.
Infos
- locate: https://www.man7.org/linux/man-pages/man1/locate.1.html
- mlocate: https://www.unix.com/man-page/Linux/1/mlocate/
- plocate: https://www.mankier.com/1/plocate
- slocate: https://linux.die.net/man/1/slocate
- updatedb: https://www.unix.com/man-page/linux/8/updatedb/
- plocate-build: https://plocate.sesse.net/plocate-build.8.html
- io-uring AIO framework: https://blogs.oracle.com/linux/post/an-introduction-to-the-io-uring-asynchronous-io-framework
- plocate's speed: https://www.linuxuprising.com/2021/09/plocate-is-much-faster-locate-drop-in.html
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.