Skip to main content

Fd Cheatsheet

Syntax Reminder

fd [FLAGS] [PATTERN] [PATH]

Pattern is regex by default. PATH defaults to . if omitted.

Core Searching

GoalCommand
Basic search (regex)fd pattern
Search specific dirfd pattern /var/log
Glob mode (like find)fd -g "*.conf"
Literal stringfd -F "192.168.1.1"
Case sensitivefd -s pattern
Case insensitivefd -i Pattern

Scope Control (Ignore Ladder)

GoalCommand
Include hidden filesfd -H pattern
Ignore .gitignorefd -I pattern
Search EVERYTHINGfd -uu pattern
Exclude a pathfd -E node_modules pattern
Max depthfd -d 2 pattern

Type and Extension

GoalCommand
Files onlyfd -t f
Directories onlyfd -t d
Executablesfd -t x
Empty filesfd -t e -t f
By extensionfd -e py
Multiple extensionsfd -e js -e ts -e jsx

Size and Time

GoalCommand
Larger than 1 GBfd -S +1g
Smaller than 10 MBfd -S -10m
Changed this weekfd --changed-within 1w
Older than 1 monthfd --changed-before 1mo

Execution

GoalCommand
Run per file (parallel)fd -e jpg -x chmod 644
Run once for all (batch)fd -e js -X eslint
Limit parallelismfd -x cmd -j 1

{} Placeholders

PlaceholderValueExample
{}Full path./src/main.rs
{/}Basenamemain.rs
{//}Parent dir./src
{.}Path no ext./src/main
{/.}Basename no extmain

Output Formatting

GoalCommand
Absolute pathsfd pattern -a
Long format (ls -l)fd pattern -l
Null-delimitedfd pattern -0
Strip ./ prefixfd --strip-cwd-prefix

Ready-to-Paste Pipelines

# Find and replace in all Python files
fd -e py -0 | xargs -0 sed -i 's/old_func/new_func/g'

# Batch convert audio files
fd -e flac -x ffmpeg -i {} -b:a 320k {.}.mp3

# Delete all __pycache__ directories
fd __pycache__ -t d -X rm -rf

# Zip all config files
fd -e conf -X zip configs.zip

# Open a file interactively with fzf
fd -t f | fzf | xargs vim