A modern search tool

Command Line – plocate

© Lead Image © Author, 123RF.com

© Lead Image © Author, 123RF.com

Article from Issue 254/2022
Author(s):

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.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: Grep

    Once you understand the intricacies of grep, you can find just about anything.

  • Admin Workshop: Finding Files

    Modern computers with their multiple Gigabyte hard disks store thousands of files. A lost file can cause a lot of work,and it can also pose a security risk. Fortunately,Linux has some versatile tools for finding those “lost files.”

  • KTools: Kdict

    Don’t worry if your memory lets you down. All you need is a place to look for answers. If you want definitions, explanations, and vocubulary, Kdict, KDE’s dictionary utility, is the tool you need.

  • Programming Snapshot – Go

    To find files quickly in the deeply nested subdirectories of his home directory, Mike whips up a Go program to index file metadata in an SQLite database.

  • Scalpel

    The Scalpel file carver helps users restore what they thought were lost files.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News