Skip to main content

Anatomy of the Fd Command

fd flips the traditional find syntax on its head. Instead of defining the path first and the pattern as an obscure flag, fd places the search pattern front and center.

The basic structure is:

fd [FLAGS/OPTIONS] [PATTERN] [PATH]

1. The Pattern (Implicit First Argument)

If you type a string without any flags, fd assumes it is the search pattern. By default, this pattern is treated as a Regular Expression (not a basic glob), and it matches against any part of the filename or path.

# Search for files containing "config" anywhere in their name/path
fd config

Note: In find, you would type find . -name "*config*". In fd, the wildcards are implicit.

2. The Path (Optional Second Argument)

If you provide a second argument that doesn't start with a dash, fd assumes it is the directory to search within. If omitted, it defaults to the current directory (.).

# Search for "nginx" inside /etc
fd nginx /etc

# Search for "app.js" inside /var/www
fd app.js /var/www

3. Options and Flags

Flags modify the behavior of the search. They can be placed anywhere, but it is conventional to place them before the pattern.

Common Flags:

  • -t, --type: Filter by file type (file, directory, symlink).
  • -e, --extension: Filter by file extension.
  • -H, --hidden: Include hidden files and directories.
  • -I, --no-ignore: Ignore .gitignore files.
  • -x, --exec: Execute a command for each search result.

Combining it all:

# Find hidden files (-H) of type file (-t f) matching "secret" in /home
fd -H -t f secret /home

Breaking the Implicit Rules

Because fd uses implicit ordering, there is a risk of ambiguity if your pattern or path looks like a flag (starts with -).

If you are searching for a literal string that begins with a dash (e.g., -test), you must use the standard POSIX double-dash -- to signal the end of options.

# Searches for the string "-test" in the current directory
fd -- -test

Similarly, if you want to search for everything in a specific path, but want to provide the path argument without a pattern argument, you use a dot . as a "match everything" regex.

# List everything in /var/log
fd . /var/log