Forget the locate command, plocate is the better choice

Author : xuzhiping   2022-11-14 14:44:41 Browse: 1033
Category : Python

Abstract: plocate looks for all files on the system that match the given pattern. Based on locate to provide faster searches on smaller ind...

plocate looks for all files on the system that match the given pattern. Based on locate to provide faster searches on smaller indexes. When you need to search for certain files in Linux, you may usually use the find or locate commands. Now, though, you have a command called plocate.

plocate works by creating an inverted index on a triple (a combination of three bytes) in the search string, which allows it to quickly narrow down the candidate set to a very small list instead of linearly scanning each entry.

plocate takes its name from the inverted index that inspired it, intended to replace mlocate. While it can still be updatedb used to create its database, plocate can also use the plocate-build utility to create indexes.

Unlike mlocate, when searching for multiple strings, plocate returns only files that match all search strings, not any files that match one string.

Using Plocate should enable a faster positioning implementation because it leverages liburing to leverage IO_uring and libzstd for faster I/O and compression of update databases.

To show the speed of the plocate command, the developers showcased this benchmark on the tool's homepage, where plocate was able to find 2 of the 27 million files in milliseconds:

Plocate

The tool has been developed rapidly. For example, Fedora 36 plans to use plocate and its locate as a new provider of commands to find files on the file system.

Installation

Installation

Debian 11 Bullseye and later, Debian 10 Buster backward migration, Ubuntu 21.04,21.10 and later:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install plocate

Arch Linux and its derivatives:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo pacman-S plocate

Fedora:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo dnf install plocate

How to use plocate

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

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo updatedb

The plocate trigger command to find files is very simple and straightforward. For example, to search for a file named linuxmi.com.py type:

Linuxmi@linuxmi:~/www.linuxmi.com$ plocate linuxmi.com.py

If you cannot find some files, there may be two culprits:

1.First, check to see if 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 periodically. You can enable it and it will automatically trigger the service:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo systemctl enable plocate-updatedb.timer

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo systemctl start plocate-updatedb.timer

2.Another reason the file is not displayed is usually permissions. Check to see if you can find these files as root, and if so, the problem is most likely that you don't have permission to access the directory all the time from the root.

For more information about the plocate command in Linux, see its man page.

Label :
    Sign in for comments!
Comment list (0)

Powered by TorCMS (https://github.com/bukun/TorCMS).