fd: simple, fast and user-friendly alternative to find

fd is a simple, fast and user-friendly alternative to find

Features

  • Convenient syntax: fd PATTERN instead of find -iname '*PATTERN*'.
  • Colorized terminal output (similar to ls).
  • It’s fast (see benchmarks below).
  • Smart case: the search is case-insensitive by default. It switches to case-sensitive if the pattern contains an uppercase character*.
  • Ignores hidden directories and files, by default.
  • Ignores patterns from your .gitignore, by default.
  • Regular expressions.
  • Unicode-awareness.
  • The command name is 50% shorter* than find :-).
  • Parallel command execution with a syntax similar to GNU Parallel.

Benchmark

Let’s start with find:

Benchmark #1: find ~ -iregex '.*[0-9]\.jpg$'

  Time (mean ± σ):      7.236 s ±  0.090 s

  Range (min … max):    7.133 s …  7.385 s
Benchmark #2: find ~ -iname '*[0-9].jpg'

  Time (mean ± σ):      3.914 s ±  0.027 s

  Range (min … max):    3.876 s …  3.964 s

Now let’s try the same for fd

Benchmark #3: fd -HI '.*[0-9]\.jpg$' ~

  Time (mean ± σ):     811.6 ms ±  26.9 ms

  Range (min … max):   786.0 ms … 870.7 ms
Benchmark #4: fd '[0-9]\.jpg$' ~

  Time (mean ± σ):     123.7 ms ±   6.0 ms

  Range (min … max):   118.8 ms … 140.0 ms

Parallel command execution

If the -x/--exec option is specified alongside a command template, a job pool will be created for executing commands in parallel for each discovered path as the input. The syntax for generating commands is similar to that of GNU Parallel:

  • {}: A placeholder token that will be replaced with the path of the search result (documents/images/party.jpg).
  • {.}: Like {}, but without the file extension (documents/images/party).
  • {/}: A placeholder that will be replaced by the basename of the search result (party.jpg).
  • {//}: Uses the parent of the discovered path (documents/images).
  • {/.}: Uses the basename, with the extension removed (party).
# Convert all jpg files to png files:
fd -e jpg -x convert {} {.}.png

# Unpack all zip files (if no placeholder is given, the path is appended):
fd -e zip -x unzip

# Convert all flac files into opus files:
fd -e flac -x ffmpeg -i {} -c:a libopus {.}.opus

# Count the number of lines in Rust files (the command template can be terminated with ';'):
fd -x wc -l \; -e rs

Installation

# MacOS brew
brew install fd

# or from source
cargo install fd-find # bcs rust...