The Linux fd command is an quick and efficient way to find files in the terminal. Like the find command, it comes in handy often, however, the find command can be a bit tricky for those new to Linux and especially it’s command line. This guide will help you get up to speed with this very useful command line tool.
It might surprise you to find out that according to some benchmarks done by the developer, fd is actually faster than find when it comes to regular expression searches. You can read all about that here.
You can find the developer’s Github page right here where they have tons of useful, well written documentation on the program and even some speed testing benchmarks with surprising results.
Here is the distro breakdown, to keep it simple:
For Debian based distributions like Ubuntu, you’ll have to download and install the command files from github like so:
alex@sudoadmins:~$ wget https://github.com/sharkdp/fd/releases/download/v7.3.0/fd-musl_7.3.0_amd64.deb alex@sudoadmins:~$ sudo dpkg -i fd-musl_7.3.0_amd64.deb
alex@sudoadmins:~$ pacman -S fd
alex@sudoadmins:~$ dnf install fd-find
alex@sudoadmins:~$ zypper in fd
alex@sudoadmins:~$ emerge -av fd
While fd is a simple command at heart, it still gives you options. As usual, the man/help pages are the best places to start:
# The following three work essentially the same. alex@sudoadmins:~$ man fd alex@sudoadmins:~$ fd -h alex@sudoadmins:~$ fd --help
# Use this to find the default Apache host config files. alex@sudoadmins:~$ fd 000 /etc/apache2 sites-available/000-default.conf sites-enabled/000-default.conf # Use this to find relevant logs. alex@sudoadmins:~$ fd log /var/log # [...] You might see a lot here, depending on your system.
Take a good look at the flags and options in the man pages. We can use these too! Try these examples. We can use use the “H” and “L” flags to make our search include hidden files and folders, and symbolic links.
alex@sudoadmins:~$ fd -HL myfile /
Use the “t” or “–type” option to filter by type and specify “f” to only show results that are files, rather than folders, executables, etc.
alex@sudoadmins:~$ fd -tf myfile /
Here is an excerpt from the man pages, in regards to filtering by type:
-t, --type <filetype>... Filter by type: file (f), directory (d), symlink (l), executable (x), empty (e)
All in all, the Linux fd command is a super simple tool for locating files primarily by name. You might even opt to use fd over find for lengthy regular expression searches! Both beginners and experienced users will likely find it very useful for its simplicity and speedy execution.1