How to Find Files with the fd Command in Linux

Finding files under a Linux operating system is a skill set that most Linux users have mastered and perfected. Linux command-line tools like the find command are very reliable and effective when handling file-finding tasks. However, using the find command to retrieve misplaced files on a Linux operating system environment is not everyone’s cup of tea due to its non-user-friendly tag.

The fd command is a user-friendly alternative to the usage complexity of the find command. It is a simple and fast file-finding command-line-based tool. Despite fd not having the functionality depth of find, the functionalities it offers are sufficient for most of your use cases and you might not even miss its alternative.

[ You might also like: Ripgrep – The Fastest Command Line Search Tool for Linux ]

fd Command Features

  • The fd command is packaged with a very intuitive syntax. For example, the find command adheres to the syntax find -iname '*PATTERN*'. On the other hand, the fd command syntax is as straightforward as fd PATTERN.
  • It supports glob-based and regular expression patterns.
  • Parallelized directory traversal makes it a very fast file finding utility.
  • Helps a user distinguish the various file types it finds by using colors to differentiate its search results.
  • Compatible with parallel command execution.
  • By default, files are searched via a case-insensitive algorithm. You can only switch to a case-sensitive algorithmic search if the search pattern contains an upper case character.
  • Hidden files and directories are automatically ignored.
  • Any pattern specified under the .gitignore file is automatically ignored.
  • In comparison to the find command implementation, the fd command is shorter hence quicker to implement.

How to Install fd Command in Linux

Depending on your Linux operating system distribution, you can install fd file-finding tool from either of the following commands:

$ sudo apt install fd-find         [On Debian, Ubuntu and Mint]
$ sudo dnf install fd-find         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -av fd               [On Gentoo Linux]
$ sudo pacman -S fd                [On Arch Linux]
$ sudo zypper in fd                [On OpenSUSE]  
$ sudo apk add fd                  [On Alpine Linux]   

How to Use fd Command in Linux

The first step is to familiarize yourself with fd’s command options. On your terminal, execute either of the following commands:

$ fdfind -h
OR
$ fdfind --help
fd Command Help
fd Command Help

Find Files in Linux

Since fd file-finding utility targets your filesystem entries, you only need to specify a single argument that relates to the file name you are interested in finding.

For example, we could be looking for a file with the pattern ‘rhel’ as part of its name.

$ fdfind rhel
fd - Find Files in Linux
fd – Find Files in Linux

As you can see, folders and directories have been highlighted in blue, images in purple, and related file names in white. This search output approach makes it easy to locate your targeted file name.

Finding Files Using Regular Expressions

Let us for example assume we are after a file name that starts with “How” and has a “.docx” file extension, we would implement the search query in the following manner.

$ fdfind 'how*.docx' -g
fd - Find Files Using Regular Expressions
fd – Find Files Using Regular Expressions

Finding Files Inside a Specific Directory

If you know the directory where your file resides, you can include its path together with the fdfind command. For instance, we can search for a file name with the pattern “command” under the below specified directory path.

$ fdfind command ~/Documents/Work/LinuxShellTips
fd - Find Files in Directory
fd – Find Files in Directory

Listing Files Recursively in Linux

By default, running the command fdfind without any arguments will recursively list all the directory files present on that parent working directory (pwd).

$ fdfind
fd - Listing Files Recursively
fd – Listing Files Recursively

Finding Files Based on Extension

If you can only identify a file based on its extension, you can apply the following command use case. The following command finds files with the “.txt” extension.

$ fdfind -e txt
fd - Find Files by Extension
fd – Find Files by Extension

Finding Hidden Files

To trace hidden files, include the command option "-H" together with the full or partial name of the file.

$ fdfind -H gitignore 
fd - Find Hidden Files in Linux
fd – Find Hidden Files in Linux

The fd command might have changed its usage syntax to fdfind but not its impressive functionality. It is still a powerful, user-friendly, and reputable file-finding tool for normal or advanced usage. More on its usage can be found on its man page.

$ man fdfind

Got something to say? Join the discussion.