linuxkernel.com

fd cheat sheet

replaces find

Find files with a simple syntax and sane defaults.

Compiled from official documentation. Click any command for details & copy · press / to search.

Basic Pattern Matching

fd <pattern>Search current directory recursively for entries matching pattern (regex by default, smart case)
fd <pattern> <dir>Search for pattern starting from a specific root directory
fdList all files recursively in the current directory (no pattern = match everything)
fd '^x.*rc$'Use a full regular expression — here: filenames starting with 'x' and ending with 'rc'
fd -g <glob>Match using a glob pattern instead of a regular expression
fd -p <pattern>Match pattern against the full path, not just the filename
fd -p -g <glob>Match a glob pattern against the full path
fd --and <pattern2>Add an additional pattern that results must also match (logical AND)

Case Sensitivity

fd <pattern>Default smart case: case-insensitive unless pattern contains an uppercase letter
fd -s <pattern>Force case-sensitive matching
fd -i <pattern>Force case-insensitive matching regardless of uppercase in pattern

Extension & Type Filters

fd -e <ext>Find files with a specific file extension (no leading dot needed)
fd -e <ext1> -e <ext2>Find files matching any of multiple extensions
fd -e <ext> <pattern>Combine extension filter with a pattern
fd -t fFilter to regular files only (aliases: file)
fd -t dFilter to directories only (aliases: dir, directory)
fd -t lFilter to symbolic links only (alias: symlink)
fd -t xFilter to executable files only (alias: executable)
fd -t eFilter to empty files and directories only (alias: empty)
fd -t sFilter to sockets only (alias: socket)
fd -t pFilter to named pipes (FIFOs) only (alias: pipe)
fd -t cFilter to character devices only (alias: char-device)
fd -t bFilter to block devices only (alias: block-device)

Hidden & Ignored Files

fd -H <pattern>Include hidden files and directories (those starting with .) in results
fd -I <pattern>Do not respect .gitignore, .fdignore, or .ignore files
fd -u <pattern>Unrestricted: equivalent to -HI — search everything, no exclusions
fd -E <glob>Explicitly exclude entries matching a glob pattern
fd -E '*.bak'Exclude files by extension pattern
fd --ignore-contain <name>Ignore directories that contain a file or directory with the given name (e.g., CACHEDIR.TAG)
fd --no-require-gitRespect .gitignore files even in directories that are not git repositories

Depth Control

fd -d <n>Limit search to at most n levels of directory depth
fd --max-depth <n>Long form of -d: limit maximum recursion depth
fd --min-depth <n>Only show results at least n directory levels deep
fd --exact-depth <n>Only show results at exactly n directory levels deep

Advanced Filters

fd -S <size>Filter by file size. Suffixes: k/m/g/t (SI) or ki/mi/gi/ti (binary). Prefix + for larger, - for smaller
fd --changed-within <date|dur>Show files modified more recently than a date or duration (alias: --changed-after)
fd --changed-before <date|dur>Show files modified before a date or duration
fd -o <user:group>Filter by owning user and/or group
fd -LFollow symbolic links (traverse them during search)
fd --one-file-systemDo not cross filesystem boundaries (aliases: --mount, --xdev)
fd --pruneDo not recurse into matching directories (prune them from traversal)

Execution (-x and -X)

fd <pat> -x <cmd>Execute command once per result in parallel; {} is replaced by the path
fd <pat> -X <cmd>Execute command once with ALL results passed as arguments (batch mode)
fd -e jpg -x convert {} {.}.pngConvert each JPEG to PNG using ImageMagick; {.} strips the extension
fd -e h -e cpp -x clang-format -iRun clang-format in-place on every C/C++ source and header file
fd -tf -x md5sum > checksums.txtCompute MD5 checksums for all regular files in parallel and save to a file
fd -e cpp -e h -X rg 'std::cout'Search all C++ files for a pattern using ripgrep in one invocation
fd -j 1 <pat> -x <cmd>Run exec commands serially (1 thread) instead of in parallel
fd <pat> -x cmd \;Use \; to terminate the command template, allowing fd flags after the command
fd --batch-size <n> -X <cmd>Limit the number of results passed per -X invocation (useful for arg-length limits)
fd -H '^\.DS_Store$' -tf -X rm Delete all .DS_Store files found recursively, including hidden directories
fd -t f -e log --changed-before 30days -X rm Delete all log files older than 30 days — no confirmation, permanent deletion
fd -t d -g node_modules -X rm -rf Recursively delete all node_modules directories — extremely destructive

Exec Placeholder Syntax

{}Full path of the matched entry
{.}Path without the file extension
{/}Basename only (filename without any leading path)
{//}Parent directory of the matched entry
{/.}Basename without the file extension

Output & Display

fd -a <pattern>Show absolute paths instead of paths relative to the current directory
fd -l <pattern>Long listing format showing permissions, size, modification time (like ls -l)
fd -0 <pattern>Separate results with NULL bytes instead of newlines (safe for filenames with spaces/newlines)
fd -c always <pattern>Force colored output even when piping (options: auto, always, never)
fd --format <template>Print results using a custom template (uses same placeholder syntax as --exec)
fd --hyperlink <pattern>Add OSC 8 terminal hyperlinks to output paths (options: auto, always, never)
fd -q <pattern>Quiet mode: suppress output, exit with code 0 if any match found, 1 if none

Piping & Shell Integration

fd -e rs | xargs -0 wc -lPipe NULL-separated results to xargs for safe argument passing
fd | tree --fromfileVisualize fd results as a directory tree using the tree command
fd --type file | fzfPipe fd results into fzf for interactive fuzzy selection
export FZF_DEFAULT_COMMAND='fd --type file'Set fd as fzf's default file listing backend (add to shell rc file)
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"Make Ctrl-T in fzf also use fd (set after FZF_DEFAULT_COMMAND)
fd --gen-completions <shell>Generate shell completion scripts (bash, zsh, fish, powershell)
fd --base-directory <dir>Execute fd as if run from the given directory (changes relative path output)
fd --search-path <dir>Supply additional search paths (can be repeated; alternative to positional path argument)

Ignore File Configuration

~/.config/fd/ignoreGlobal ignore file (Linux/macOS) — glob patterns, one per line, always applied
%APPDATA%\fd\ignoreGlobal ignore file path on Windows
.fdignorePer-project ignore file, same gitignore syntax — place at repo root or any parent
.ignoreGeneric ignore file also respected by ripgrep and ag (silver searcher)
fd -IOverride all ignore files for a single run

Killer recipes

Interactive file opener with fzf + bat preview

fd --type f --hidden --exclude .git | fzf --preview 'bat --style=numbers --color=always {}' | xargs -o $EDITOR

Find all non-ignored files, select interactively with fzf showing a syntax-highlighted preview via bat, then open the chosen file in $EDITOR. The -o flag in xargs keeps stdin for the editor.

Search file contents across a filtered set with ripgrep

fd -e ts -e tsx --exclude node_modules -X rg 'useEffect'

Collect all TypeScript/TSX files (excluding node_modules) and pass them all at once to ripgrep — faster than rg alone when you want to pre-filter by name or location before searching contents.

Bulk image conversion in parallel

fd -e jpg -e jpeg -t f -x convert {} {.}.webp

Convert every JPEG to WebP in parallel using ImageMagick. The {.} placeholder strips the extension so you get file.webp instead of file.jpg.webp. Parallelism is automatic with -x.

Find and view large files with eza details

fd -t f -S +50m | sort | xargs eza -lh --color=always

Find all files larger than 50 MB, then display them with eza's long listing for human-readable sizes, permissions, and timestamps in one readable table.

Safe stale log cleanup (dry-run first)

fd -t f -e log --changed-before 30days && fd -t f -e log --changed-before 30days -X rm

First run lists all log files older than 30 days so you can review. The second command (after &&) actually deletes them. Split into two steps to avoid accidental deletion.

fzf directory jumper (replace cd)

cd "$(fd --type d --hidden --exclude .git | fzf)"

Interactively fuzzy-find any directory (including hidden ones like .config) and cd into the selection. Wrap this in a shell function (e.g., named 'fcd') for daily use.

Notes & tips

SMART CASE fd is case-insensitive by default. It automatically switches to case-sensitive mode the moment your pattern contains any uppercase letter. Override with -s (always sensitive) or -i (always insensitive).
REGEX vs GLOB fd uses regular expressions by default, not glob patterns. Use -g to switch to glob syntax. Regex patterns match as substrings (no anchoring needed); use ^ and $ to anchor.
IGNORE HIERARCHY fd respects .gitignore, .fdignore, .ignore, and the global ignore file (~/.config/fd/ignore on macOS/Linux). Each layer can be bypassed: -I disables all ignore rules, --no-require-git makes fd respect .gitignore even outside git repos.
EXEC PARALLELISM -x runs one process per result in parallel by default. Use -j 1 (or --threads=1) for serial execution. -X (exec-batch) runs exactly one process with all results as arguments — beware arg-length limits for very large result sets; use --batch-size to chunk them.
HIDDEN FILES DEFAULT Hidden files (dotfiles) are excluded unless you pass -H or -u. This includes .git directories, .env files, etc.
PLACEHOLDER DEFAULT If you use -x or -X without any placeholder ({}, {.}, etc.) in your command, fd automatically appends {} at the end.
NULL OUTPUT (-0) Always use -0 with xargs -0 when filenames may contain spaces or newlines. This is the safe default for piping.
FZF INTEGRATION Setting FZF_DEFAULT_COMMAND='fd --type file' makes every fzf invocation (including Ctrl-T in the shell) use fd. Add --hidden --follow --exclude .git to also include dotfiles while ignoring .git internals.
LS_COLORS fd respects the LS_COLORS environment variable for colorizing output, same as ls. Also honors the NO_COLOR environment variable to disable color.
PERFORMANCE fd uses parallel directory traversal and is roughly 23x faster than find -iregex on typical workloads per the official benchmarks.
VERSION NOTE This reference covers fd v10.x (latest: v10.4.2). The --ignore-contain, --hyperlink, --format, and --exact-depth flags are v8+/v10+ features and may not be present on older installs.