Two tools for finding files in the file system are recommended

As we all know, in Linux or Unix like file systems, if you want to find a file through the file name keyword, you can use the find Command. Then this article will recommend two tools that can quickly find files, which have better performance than the find command and can replace the use of find in some scenarios.


Most Linux distributions provide the mlocate package, which includes a locate The command is used to find files, and a updatedb The command updates the file index for use by locate.

It can be installed directly through the software package management tool of the system

$ sudo dnf install mlocate

# Debian/Ubuntu
$ sudo apt install mlocate

After installation, first execute the following commands to index the files

sudo updatedb

The index file will be stored in / var/lib/mlocate/mlocatedb by default. You can also modify the configuration file / etc/updatedb.conf to add some folders that do not need index, such as

# Paths which are pruned from updatedb database
PRUNEPATHS="/tmp /var/tmp /var/cache /var/lock /var/run /var/spool /mnt /cdrom /usr/tmp /proc /media /sys /.snapshots /var/run/media"

After indexing, you can use the locate < pattern > command to find files, for example

$ locate mlocate

You can use the - b option for exact matching, such as the difference between the results of the following two queries

$ locate -b '\updatedb'

Note that when using - b, you need to use \ beforethe key of search.

$ locate 'updatedb'

You can also use - r for basic regular expression pattern matching. You can view locate --help or man locate.

Next, we will introduce another find alternative Ping - fd.


fd It's a product made by David Peter The open source tool developed is used to find files in the file system. In most cases, it can replace the find command.

fd can be used on multiple platforms, including most Linux distributions, MacOS and Windows. The specific installation can be viewed .

For example, you can use HomeBrew/LinuxBrew for installation

$ brew install fd

After installation, you can use it directly, for example, to find files with png extension in the current folder

$ fd -e png

Note that the default search path of fd command is the current directory. You can use -- base directory or -- search path to specify the search path. For example, we can find the regular files matching docker under / etc /

$ fd --base-directory /etc/ -t f 'docker'

You can also use the - x option to output the results to other commands for operation (similar to the -- exec option of the find command), such as

$ fd -d 1 -e png -x convert {} {.}.jpg

This will find all PNG files in the current directory and convert them to JPG files. Placeholders {} and {.} are used in the above command. See the following example to show the results represented by the placeholder

❯ fd 'recognition.db' -x echo {}

❯ fd 'recognition.db' -x echo {.}

❯ fd 'recognition.db' -x echo {/}

❯ fd 'recognition.db' -x echo {//}

❯ fd 'recognition.db' -x echo {/.}

Through placeholders, you can easily operate on files. For more fd command options, you can view fd --help.

If you want to use fd on Windows, you can install it through the Scoop package manager and open PowerShell

-> scoop install fd


Here are two tools for quickly finding files through file name matching in the file system. mlocate uses index files, so it is very efficient in finding files globally. The fd tool provides many functions, which can be used instead of the find command in most scenarios, and its performance is also higher than that of the find command. In addition, the developers of fd tool have also developed other practical tools besides this tool, such as bat -A tool that can replace the cat command. It is also recommended to output the file content in the form of syntax highlighting in many other programming languages.

Also published in Mengz's Blog

Tags: Linux find

Posted on Fri, 03 Dec 2021 09:24:41 -0500 by mrdance