A terminal window on a Linux PC with an Ubuntu-style desktop.
Fatmawati Achmad Zaenuri/Shutterstock

On Linux, fd is an easier alternative to the find command. It has a simplified syntax, uses sensible defaults, and has built-in common-sense behavior. Let’s take it through its paces.

fd versus find: What’s the Difference?

The fd command isn’t meant to replace the traditional find command, which has been on Linux, well, forever. Instead, fd tries to satisfy the majority of common uses of find in a more straightforward way—and, it’s often eight or nine times faster than find. You can see some of its benchmarks on the project’s GitHub repository page.

fd has a colorized output, similar to that of some ls modes. It’s recursive, but doesn’t search hidden directories by default. It knows about Git and will also automatically ignore any patterns in your “.gitignore” file.

fd is case insensitive by default. However, if your search pattern contains an uppercase letter, fd operates in a case sensitive mode. Of course, you can override the defaults, but, in many cases, they work in your favor.

RELATED: How to Use All Linux's Search Commands

Installing fd

Since Ubuntu 19.04 (Disco Dingo,) you can install fd directly by calling the officially maintained package with apt-get. If you’re running an older version of Ubuntu, check the installation instructions on the Git hub page.

Type the following:

sudo apt-get install fd-find

sudo apt-get install fd-find in a terminal window.

In Ubuntu, the command is fdfind to avoid a name clash with another existing utility. If you want it to be fd, you can set up an alias:

alias fd=fdfind

alias fd=fdfind in a terminal window.

To make the alias persistent so it will remain available after reboots, put it in your “.bashrc” or “.bash_aliases” file.

RELATED: How to Create Aliases and Shell Functions on Linux

To install fd on Fedora, type this command:

sudo dfn install fd-find

sudo dnf install fd-find in a terminal window.

On Manjaro, type the following:

sudo pacman -Syu fd

sudo pacman -Syu fd in a terminal window.

fd versus fdfind

To avoid confusion, we’ve left the command with its default name, fdfind, on our Ubuntu test PC. fd and fdfind are exactly the same command, as you’ll see in the following example (if you ask fdfind to show its version, it calls itself “fd”):

fdfind --version

fdfind --version in a terminal window.

We’ll call the command “fed,” but in the examples, we’ll use the Ubuntu “fdfind.” On other Linux distributions, you can type “fd” instead of “fdfind” to save a few keystrokes.

Simple Searches with fd

If you use fd with no command-line options, it behaves a little like ls, except it lists files in subdirectories by default.

Type the following:


fdfind in a terminal window.

The output appears in different colors for different file types and directories.

Output from fdfind in a terminal window.

To see files of a specific type, use the -e (extension) option. Note that you don’t have to precede the extension with a period (.), nor is it case sensitive.

For example, you could type the following:

fdfind -e png

fdfind -e png in a terminal window.

Now, the only files listed are PNG image files.

output of fdfind -e png in a terminal window.

To look for a single file, type its name on the command line, like so:

fdfind index.page

fdfind index.page in a terminal window.

The file is found and happens to be in a subdirectory. We didn’t have to tell fd to search recursively.

To have the search start in a particular directory, include a file path on the command line. The following command will start a search in the “/etc” directory, and look for files that include “passwd” in the file name:

fdfind passwd /etc

fdfind passwd /etc in a terminal window.

Here, we’re searching for all C source code files that contain “coord” in the file name:

fdfind -e c coord

fdfind -e c coord in a terminal window.

Two matching files were found.

fd and Git

Git is an extremely popular source code version control system. If you use Git on your computer, you probably use “.gitignore” files to tell Git which files it should concern itself with, and which it can ignore. By default, fd respects the settings in your “.gitignore” files.

In this directory, we’ve got a Git repository and “.gitignore” file. We type the following:

ls -adl .git*

ls -adl .git* in a terminal window.

Let’s ask fd to list any files that contain “coord” in the file name. We’ll then repeat the search and use the -I (no ignore) option. This tells fd to ignore the settings in the “.gitignore” file and report every matching file.

To do all of this, we type the following:

fdfind coord
fdfind coord -I

fdfind coord in a terminal window.

The two extra files in the second set of results are object files. These are created when a file program is compiled. They’re then used by the linker to create the final executable version of the program.

Object files are typically ignored by source code version control programs. They’re regenerated every time you compile your program, so you don’t have to store copies of them. There’s an entry in the “.gitignore” file that instructs Git to ignore object files, and, by default, fd ignores them, too.

The -I (no ignore) option forces fd to return everything it finds, rather than being guided by the “.gitginore” file.

File Types and Case Sensitivity

You can ask fd to look for directories, files (including those that are executable and empty), and symbolic links. You can do so by using the -t (type) option, followed by one of the letters below:

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

The following looks for a directory called images:

fdfind -td images

fdfind -td images in a terminal window.

A match is found, one subdirectory lower than the current one.

Let’s see how case sensitivity works with search patterns. We type the following to first search for files that contain “geo” in their file names, and then for those that contain “Geo” in their file names:

fdfind -tf geo
fdfind -tf Geo

fdfind -tf geo in a terminal window.

In the first command, we used a lowercase search pattern, which caused fd to operate in a case-insensitive way. This means both “Geo” and “geo” are valid matches.

Our second command contained an uppercase character, which caused fd to operate in a case-sensitive manner. This means only “Geo” is a valid match.

Command Execution

The fd command allows you to launch another command and execute it on each of the found files.

Let’s say we know there’s a Zip file somewhere in our source code directory tree. We can look for it using the following command, which searches for files with the ZIP extension:

fdfinf -e zip

fdfinf -e zip in a terminal window.

With the -x (exec) option, you can pass each found file to another command to be processed by it. For example, we can type the following to call the unzip utility to unzip our ZIP file (the “{}” is a placeholder representing the found file):

fdfind -e zip -x unzip {}

This will unzip the file in the current working directory. If we want it to be unzipped in the directory containing the ZIP file, we can use one of the following placeholders:

  • {}: 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 our ZIP file to be found and unzipped in the directory that contains it, we can use the unzip -d (directory) option, and pass in the parent directory placeholder ({//}):

fdfind -e zip -x unzip {} -d {//}

fdfind-e zip -x unzip {} -d {//} in a terminal window.

The ZIP file is then located and the unzipped in its parent directory.

Output from fdfind-e zip -x unzip {} -d {//} in a terminal window.

Your Go-to Find?

Because it covers the most common uses with such simplicity, fd can easily become your go-to “find” command. Whenever you need its more advanced features, you can always return to that seasoned veteran, find.

Dave McKay Dave McKay
Dave McKay first used computers when punched paper tape was in vogue, and he has been programming ever since. After over 30 years in the IT industry, he is now a full-time technology journalist. During his career, he has worked as a freelance programmer, manager of an international software development team, an IT services project manager, and, most recently, as a Data Protection Officer. Dave is a Linux evangelist and open source advocate.
Read Full Bio »

The above article may contain affiliate links, which help support How-To Geek.