FD
On this page 2 sections
FD Cheatsheet
Basics
- Regex by default. Use -g for glob, -e for extension, -t for type (f,d,l,x).
- Ignores hidden and .gitignored files unless you add -H and/or -I, or -u for both.
Find files by name/extension
# Regex match (default)
fd '.*\.rar$' .
# Glob match
fd -g '*.rar' .
# By extension (fast, exact)
fd -e rar .
Find directories by name
fd -t d 'dirname' .
Case sensitivity
# Smart-case by default: case-insensitive unless pattern has uppercase
fd 'name' .
fd 'Name' .
# Force case-insensitive / case-sensitive
fd -i 'name' .
fd -s 'name' .
Hidden and ignored files
# Include hidden files/dirs
fd -H 'pattern' .
# Do not respect .gitignore/.ignore/.fdignore
fd -I 'pattern' .
# Unrestricted: includes hidden and ignores ignore files
fd -u 'pattern' .
Depth and path options
# Limit search depth
fd -d 2 'pattern' .
# Print absolute paths
fd -a 'pattern' .
Type, size, and time filters
# Files only / directories only
fd -t f 'pattern' .
fd -t d 'pattern' .
# Size filters (k, M, G supported)
fd -t f -S +11G .
# Modified within/before
fd --changed-within 7d .
fd --changed-before '2024-01-01' .
Exclude paths
fd 'pattern' . --exclude .git --exclude node_modules
Execute commands on results
# Per result
fd 'pattern' . -x command {}
# Batch (all results at once; safer for rm/cp/mv)
fd 'pattern' . -X command
Practical examples (similar to your find ones)
Find a file called a specific thing
fd -g '*.rar' .
Find files over 11GB and convert with ffmpeg (per-file)
fd -t f -S +11G . -x bash -lc 'date && ffmpeg -i "{}" -map 0 -map -0:t -map -0:s -c:a aac -c:v libx265 -s 1920:1080 -preset slow -crf 18 "{.}new.mp4" && rm "{}" && mv "{.}new.mp4" "{.}.mp4" && chown ed:ed "{.}.mp4" && date || echo "This task has failed"'
Find all rar archives (including multi-part .r00, .r01, …) and extract them
# Extract in place (cd to file's directory and extract its basename)
fd -t f '\.r(ar|[0-9]{2})$' . -x bash -lc 'cd "{//}" && unrar e "{/}"'
Remove all rar and multi-part files
fd -t f '\.r(ar|[0-9]{2})$' . -X rm -f
Find and count results
fd -t f -S +11G . | wc -l
Find total size of matching files
# GNU du: prints total on last line
fd -t f -S +11G -0 . | du --files0-from=- -ch | tail -n1
Other handy patterns
Copy/move found files
# Copy all .jpg to destination (batch)
fd -t f -e jpg . -X cp -t /path/to/destination # GNU cp (-t). For portability:
fd -t f -e jpg -0 . | xargs -0 -I{} cp {} /path/to/destination
Delete empty directories
fd -t d -E .git . -x bash -lc 'test -z "$(ls -A "{}")" && rmdir "{}"'
Null-delimited output (safe for spaces/newlines)
fd -0 'pattern' . | xargs -0 -I{} echo "{}"
Notes on placeholders for -x/-X
- {} full path
- {/} basename
- {//} parent directory
- {.} path without extension
- {/.} basename without extension
Examples using placeholders
# Print parent dir and base name
fd -t f . -x echo 'dir="{//}" file="{/}"'
# Run in file's directory
fd -t f . -x bash -lc 'cd "{//}" && do-something "{/}"'