Using the fd command in Linux Examples

In this article, you will learn an Ultimate Guide for Using the fd command in Linux with Examples. The fd command is an alternative to the find command but it is faster and has better performance. It also supports many features like colors. It can be used to find files and directories with their name, sizes, types, etc.

You can follow the steps below to see how you can install it on Linux distributions and start using it with examples.

Ultimate Guide for Using the fd command in Linux with Examples

Before you start, you must have access to your Linux server as a root or non-root user with sudo privileges. Then, follow the steps below to complete this guide. You can also, visit the Orcacore website and search for the Linux server setup initial guides.

Step 1 – Install fd Command on Linux

You can install the fd utility from the default package manager on most Linux distributions. To do this, follow the steps below.

Install fd on Ubuntu / Debian

On the Ubuntu and Debian-based distros, you can use the command below to install fd:

sudo apt install fd-find

Note: In Debian-based distros, fdfind is taken by another utility. If you want to use it as an fd command, you must run the command below:

alias fd=fdfind

To make it available after reboots, you need to put it in your “.bashrc” or “.bash_aliases” file.

To see if it works correctly, you can check the version installed on your server:

fd -V
Output
fdfind 8.6.0

Install fd on AlmaLinux / Rocky Linux / RHEL

On RHEL-based distros like Centos and AlmaLinux, you can use the command below to install fd tool:

sudo dnf install fd-find

Now you can follow the steps below to start using the fd command with examples.

Step 2 – Basic Usage of fd Command in Linux

The simple usage of fd is to run it without any options. It will act like the ls command, but it will list files in subdirectories by default.

fd

The output results will shown in different colors for different types and directories.

Simple search with fd command on Linux

Step 3 – Search for a Single File with fd Command in Linux

If you are looking for a specific single file, you can easily search it with the fd command without using any option. For example, we want to find the About.py file in my server:

fd About.py

The results will show the path of the desired file we have searched:

Exmaple Output
Downloads/nmap-master/zenmap/build/lib/zenmapGUI/About.py
Downloads/nmap-master/zenmap/zenmapGUI/About.py

Step 4 – Search for Files with a Specific Type with fd Command in Linux

You can also use the fd command to search for a specific type of file. In this case, you should use the -e option in the fd command with your desired type. For example, we want to find the files that have the png types:

fd -e png

The output will print the files that have the PNG types:

Exmaple Output
Downloads/nmap-master/macosx/nmap.png
Downloads/nmap-master/nping/nping-dev/packetDiagram.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/default_32.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/default_75.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/freebsd_32.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/freebsd_75.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/irix_32.png
Downloads/nmap-master/zenmap/share/zenmap/pixmaps/irix_75.png

Step 5 – Search for a File in a Particular Directory with fd Command

At this point, you can search for a file path in a particular directory with the fd command in Linux. For example, you can search for the passwd file in the /etc directory by using the fd command below:

fd passwd /etc

The output will show you the files containing passwd in the /etc directory:

Exmaple Output
/etc/pam.d/chpasswd
/etc/pam.d/passwd
/etc/passwd
/etc/passwd-
/etc/security/opasswd

Step 6 – fd command File Types and Case Sensitivity

YOu can use the fd command to search for directories, files, and symbolic links. To do this, you can use the -t option with the following letters:

  • f: File.
  • d: Directory.
  • l: Symbolic link.
  • x: Executable file.
  • e: Empty file.

For example, we want to search for the directory named zenmap:

fd -td zenmap

The output prints the directories that contain zenmap:

Exmaple Output
Downloads/nmap-master/zenmap/
Downloads/nmap-master/zenmap/build/lib/zenmapCore/
Downloads/nmap-master/zenmap/build/lib/zenmapGUI/
Downloads/nmap-master/zenmap/share/zenmap/
Downloads/nmap-master/zenmap/zenmapCore/
Downloads/nmap-master/zenmap/zenmapGUI/

Also, you can use the fd command for searching the files and directories with case sensitivity. If you use the lowercase it will show you all the results. But if you want to see the uppercase results, you can use the uppercase word. For example:

fd -td Downloads

Step 7 – Execute Other Commands with fd

At this point, you can launch another command and execute it with the fd command. For example, you have a zip file and you want to unzip the file in your current working directory. To do this, you can use the fd command as shown below:

fdfind -e zip -x unzip {}

The patterns you can use are listed below:

  • {}: The full file path and name of the found file.
  • {/}: The file name of the found file.
  • {//}: The directory containing the found file.
  • {/.}: The file name of the found file, without the extension.

For more options, you can use the man page or help command:

# fd -h
# man fd

Conclusion

As you can see fd command is much faster and has better performance than the find command. You can easily install the fd utility on Linux distributions and start using the fd command with examples that are provided for you in this guide. You can read the man page of the fd tool and get more information about its amazing options.

Hope you enjoy using it. You may be interested in these articles:

Fix Error Module Not Found named ‘distutils’

Efficiently backup and restore data on Linux with restic

dev/null in Linux and Use It with Examples

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!