Skip to content

Drill: fd as a Modern find Replacement

Goal

Use fd for fast, user-friendly file finding with type filters, regex, exec, and exclusion patterns.

Setup

  • Install fd (apt install fd-find, brew install fd, package may provide fdfind binary)
  • Note: on Debian/Ubuntu the binary is fdfind; create an alias if needed

Commands

Find files by name pattern:

fd "config"

Find with a specific extension:

fd -e yaml
fd -e py
fd -e go -e rs  # multiple extensions

Filter by type (file, directory, symlink):

fd -t f "test"      # files only
fd -t d "config"    # directories only
fd -t l             # symlinks only

Search with regex:

fd '.*_test\.go$'
fd '^Dockerfile'

Search in a specific directory:

fd -e yaml . /etc/

Exclude directories:

fd -E node_modules -E .git "*.js"

Execute a command on each result:

fd -e log -x gzip {}           # gzip each log file
fd -e tmp -x rm {}             # delete each tmp file
fd -e py -x wc -l {}           # count lines in each Python file

Execute with placeholder variations:

fd -e md -x echo "File: {/} in {//}"  # {/} = basename, {//} = parent dir

Show results with details:

fd -l -e conf  # long listing format like ls -l

Use with other tools:

fd -e go | xargs wc -l | sort -rn | head -10

Find hidden files (normally excluded):

fd -H ".env"

Find ignored files (in .gitignore):

fd -I "vendor"

What to Look For

  • fd respects .gitignore by default (like ripgrep)
  • Regex patterns are the default (no need for -regex like in find)
  • -x executes per result; -X batches all results into one command
  • Output is colorized and human-friendly by default

Common Mistakes

  • On Ubuntu/Debian, the binary is fdfind not fd (alias it in your shell rc)
  • Forgetting that fd ignores hidden files and .gitignored paths by default
  • Using shell globs instead of regex patterns in the search string
  • Not using -I when searching for files listed in .gitignore

Cleanup

No cleanup needed unless you used -x with destructive commands.