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 asfd 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
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
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
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
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
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
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
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