How to Use fd to Quickly Find Files in Linux and macOS

Use Fd On Linux Macos Hero 2

fd is a simpler alternative to the find command. It uses a truncated syntax and an abbreviated command structure to keep your typed commands short and to the point. However, that lack of verbosity that makes fd easy to type makes it more difficult to understand. fd also runs pattern-matching more rapidly than the default find commands. Learn how to use fd on Linux and macOS.

Install fd on Linux

fd doesn’t ship on many systems by default. You’ll need to use your preferred package manager to download and install the application, and then you can run it from within Terminal.

Ubuntu

It will ship on Ubuntu Disco Dingo 19.04, but otherwise you’ll need to download and install it. For Ubuntu and other Debian-based Linux distros, you’ll want to run the following commands to download and install the program.

If you need the 32-bit version or a different build, download it from the GitHub releases page for fd.

Debian

On Debian Buster or newer, you can install fd from the official Debian-maintained repository.

Fedora

From Fedora 28, fd can be installed from official package versions.

Arch Linux

Similarly, Arch users can grab fd from the official repos:

Gentoo Linux

Gentoo users can use the following command to download the fd ebuild:

macOS

If you’re running macOS, install Homebrew, then use the command below to install fd:

Using fd on Linux

Use Fd On Linux Macos Hero

fd commands have a basic structure of fd pattern compared to find . -iname 'pattern'.

To search for a file by its name, use the following command:

This searches within the preset working directory, including subdirectories. To search within a specific directory, specifying it after your search term:

Executing Commands on Results

Like find, fd has a functionality that passes found files to another command for execution. Where find uses find . -iname pattern -exec command, fd uses the -x flag:

This command would send all zip files in the directory to the unzip command. You can use the following symbols within the “phrase” of the execute command to pass information in specific ways.

  • {}: A placeholder is replaced with the path of the search result (files/images/portrait.jpg).
  • {/}: A placeholder that will be replaced by the the filename of the result only, known by UNIX aficionados as the basename (portrait.jpg).
  • {//}: Placeholder replaced with the parent directories of found items (files/images).
  • {.}: Placeholder replaced with the path to the filename, without extension (files/images/portrait).
  • {/.}: Placeholder replaced with the basename of the found item, without extension (portrait).

Consider the following example, using two of the above-cited placeholder symbols:

Other Useful fd Flags

  • -e: search the extension of files only, with no separating dot.
  • -E pattern: exclude results matching the following pattern.
  • --changed-newer-than date|duration: filter results based on the time since file modification. This will only show files with modification dates later than the specified date. The time can be given a duration that counts backwards from the present moment (10h, 1d, 35min) or can be set to a specific time ("YYYY-MM-DD HH:MM:SS").
  • –changed-older-than date|duration: Like –change-newer but will show files edited before the specified date or duration, not after.
  • -t: only show files of the specified type (-tf for files, -td for directories, -tx for executables, -tl for symlinks, -te for empty files).
  • -p: search within the entire pathname, not just the filename.
  • -s: force case-sensitivity. By default, fd ignores case unless an uppercase letter is typed in the search pattern.
  • -H: show hidden files and directories within results.
  • -L: follow links into symlinked directories.

fd is a good alternative for the find command. If your experience is that the “find” command is hard to use, then you might have better luck using fd. Try it out and let us know if it is useful to you.

One comment

  1. You have a typo on the ubuntu install it should be sudo dpkg -i fd-musl_7.3.0_amd64.deb.
    It isn’t on 19.04 ubuntu as standard
    The drill utility seems (to me at least) to be a better option, here’s a link – https://www.drill.santamorena.me/

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.