Linux fd Command: Modern Alternative to find
The traditional find utility has been a cornerstone of
Unix-like operating systems for decades, but its archaic syntax and
single-threaded execution often make routine file searches slow and
cumbersome. In modern Linux distributions, fd (often
installed as fdfind on Debian-based systems) serves as a
modern, high-performance alternative built in Rust. This article breaks
down how Linux implements fd, detailing its multi-threaded
architecture, intuitive syntax, opinionated defaults, and how it
directly improves upon the standard find command.
Parallel Directory Traversal
The primary performance bottleneck in the classic find
utility is its single-threaded, sequential traversal model. When
scanning massive directory trees or slow disk arrays, find
processes one entry at a time.
In contrast, fd leverages the concurrency primitives of
Rust via libraries like crossbeam and rayon.
During execution, fd spawns a thread pool matched to the
host machine's available CPU cores. As the filesystem tree is traversed,
directories are distributed among worker threads. This parallel walking
allows fd to saturate I/O pipelines and maximize modern
multi-core processor usage, often completing searches several times
faster than find.
Smart Defaults Out of the Box
The standard find command defaults to raw filesystem
scanning without context, requiring explicit flags to exclude unwanted
artifacts. The fd command introduces opinionated defaults
that reflect modern development workflows:
- Hidden Files and Directories:
fdignores hidden directories and files (those starting with a dot) by default. They can be included using the-H(or--hidden) flag. - Gitignore Integration:
fdnatively parses.gitignoreand.ignorefiles. Build artifacts,node_modules, and temporary cache directories are automatically excluded from search results unless overridden with-I(or--no-ignore). - Smart Case Sensitivity: Searches are
case-insensitive by default. However, if an uppercase letter is
introduced in the search query,
fdautomatically switches to case-sensitive mode (similar to Smart Case in modern text editors). Case sensitivity can be enforced with-sor disabled with-i.
Simplified Pattern Matching
The POSIX find command uses shell globbing by default
and requires verbose syntax for regular expressions:
# find syntax for regex
find . -type f -regextype posix-extended -regex '.*\.ya?ml$'The fd command assumes regular expressions by default
and provides dedicated flags for common search criteria:
# Equivalent search in fd
fd '\.ya?ml$'For file extension searches, fd provides a dedicated
-e flag, eliminating the need to write wildcard
patterns:
fd -e mdColored Output and Interactive Terminal Support
While find outputs plain text streams, fd
detects whether standard output is connected to an interactive terminal
(a TTY). When connected to a TTY, fd formats the output
using terminal color codes (respecting LS_COLORS),
highlighting file types, permissions, and directory structures. When
output is piped to a file or another command, fd
automatically strips color codes to preserve clean text processing.
Executing Commands on Search Results
Batch operations in find rely on -exec
syntax, which can be awkward:
find . -name "*.bak" -exec rm -f {} +The fd command simplifies command execution using the
-x (or --exec) flag for parallel execution or
-X (or --exec-batch) to pass all results as
arguments to a single command:
# Run command in parallel for each file
fd -e bak -x rm
# Pass all files at once to a single process
fd -e bak -X rmAdditionally, fd supports contextual placeholders, such
as {} for the full path, {/} for the basename,
and {//} for the parent directory, significantly reducing
the need for piping output to utilities like xargs or
awk.
When to Still Use find
Despite the advantages of fd, find remains
essential in specific scenarios:
- POSIX Portability: Standard shell scripts that must
run across varied Unix environments (AIX, BSD, minimal Linux containers)
depend on
findbeing present everywhere. - Complex Inode and Time Filters: Classical
findsupports hyper-specific filesystem metadata queries, such as searching by specific inode numbers (-inum) or exact access minute intervals (-amin).
For everyday interactive CLI navigation, developer workflows, and
local system management, fd delivers a substantially
faster, more intuitive interface that replaces find in
modern Linux environments.