Most Linux users are well familiar with the find command and the many cases it can be used. Today we are going to review an alternative to find command, called fd.
fd is a simple, fast, and user-friendly tool meant to simply perform faster compared to find. It is not meant to completely replace find but rather give you an easy-to-use alternative that performs slightly faster.
fd Features
Some of the notable features of fd:
- Easy to use syntax – fd *pattern* instead of find -iname *pattern*.
- Colorful output is similar to the one of the ls command.
- Fast performance. The developer’s benchmarks are available here.
- Smart search with case-insensitive by default and switches to case-sensitive if pattern containers an uppercase symbol.
- Does not look in hidden files and directories by default.
- Does not look into .gitignore by default.
- Unicode awareness.
How to Install fd in Linux
We are going to look at how to install fd in different Linux distributions using the default package manager as shown.
$ sudo apt install fd-find [On Debian, Ubuntu and Mint] $ sudo yum install fd-find [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/fd [On Gentoo Linux] $ sudo pacman -S fd [On Arch Linux] $ sudo zypper install fd [On OpenSUSE] $ sudo apk add fd [On Alpine Linux]
How to Use fd in Linux
Similar to the find command, fd has many uses cases, but let’s start by checking the available options:
# fd -h OR # fd --help
Let’s have a look at a few examples. You can run fd without any arguments, the output is very similar to the ls -R command.
# fd
In the next fd examples, I will use a default WordPress installation located in /var/www/html/
to search for different files and folders.
In the example below, I have printed only the first 10 results for the shorter output using pipe redirection with the head command.
# fd | head
Find All JPG Files in Linux
Let’s say we want to find all jpg files. We can use the “-e”
flag to filter by file extension:
# fd -e jpg
If you want to specify a search directory, you simply need to give it as an argument:
# fd <pattery> <directory>
Search for String in All PHP Files in Linux
The “-e”
flag can be used in combination with a pattern as shown:
# fd -e php index
The above command will look for files with an extension .php
and have the string “index” in them:
If you want to exclude some results, you can use the “-E”
flag as shown:
# fd -e php index -E wp-content
This command will look for all files with php extension, containing the string “index” and will exclude results from the “wp-content” directory.
Find All JPG Files and Modify Permission
Just as find, you can use -x
or --exec
arguments to perform parallel command execution with the search results.
Here is an example where we will use chmod to change the permissions of the image files
# fd -e jpg -x chmod 644 {}
The above will find all files with extension jpg and will run chmod 644 <path-to-file>
.
Here are some useful explanations and usage of the brackets:
{}
– A placeholder that will be changed with the path of the search result (wp-content/uploads/01.jpg).{.}
– similar to{}
, but without using the file extension (wp-content/uploads/01).{/}
: A placeholder that will be replaced by the basename of the search result (01.jpg).{//}
: Parent directory of the discovered path (wp-content/uploads).{/.}
: Only the basename, without the extension (01).
Conclusion
This was a brief review of the fd command, which some users may find easier to use and faster. As mentioned earlier in this article fd is not meant to completely replace find, but rather provide a simple usage, easier search, and better performance. Fd does not take much space and is a nice tool to have in your arsenal.
Installation commands are outdated, better to use a native package management system:
Follow this link: https://github.com/sharkdp/fd#installation
@Anmichel,
I have updated the fd installation instructions…
Starting with Ubuntu 19.04, the package ‘fd-find‘ can be installed the usual way. There is no need to download and install the deb file manually.
Hi,
Link to developer’s benchmark results were provided in the article, you probably missed it. I am including the link once more:
https://github.com/sharkdp/fd#benchmark
Can you back up the claims that it’s faster than the original ‘find’?
If not – this is just a bunch of code and another out of district piece of software to maintain yourself.
Looks like it was written so that the author doesn’t need to learn ‘find’ options and/or brag about a nearly useless piece of software.