تخطَّ إلى المحتوى

fd - Fast and User-Friendly Find Alternative Cheatsheet

fd - Fast and User-Friendly Find Alternative Cheatsheet

Installation

PlatformCommand
Ubuntu/Debiansudo apt install fd-find (binary: fdfind)
Arch Linuxsudo pacman -S fd
Fedora/RHELsudo dnf install fd-find
Alpine Linuxapk add fd
macOS (Homebrew)brew install fd
macOS (MacPorts)sudo port install fd
Windows (Scoop)scoop install fd
Windows (Chocolatey)choco install fd
Windows (Winget)winget install sharkdp.fd
Cargo (All platforms)cargo install fd-find
Snapsudo snap install fd
Note: On Debian/Ubuntu, create symlink: ln -s $(which fdfind) ~/.local/bin/fd

Basic Commands

CommandDescription
fd filenameSearch for files/directories matching “filename”
fd pattern /pathSearch for pattern in specific directory
fd -e txtFind all files with .txt extension
fd -e js -e tsFind files with multiple extensions (.js or .ts)
fd -t f patternFind only files (not directories)
fd -t d dirnameFind only directories
fd -t xFind only executable files
fd -t lFind only symbolic links
fd -s PatternCase-sensitive search (default is case-insensitive)
fd -d 3 patternLimit search depth to 3 levels
fd -H patternInclude hidden files in search
fd -I patternDon’t respect .gitignore rules
fd -a patternShow absolute paths instead of relative
fd -l patternShow detailed listing (like ls -l)
fd -0 patternUse null separator (for piping to xargs -0)

Advanced Usage

CommandDescription
fd '^test.*\.js$'Use regex pattern (files starting with “test”, ending with .js)
fd -g '*.{js,ts}'Use glob patterns instead of regex
fd -F 'exact.string'Fixed string search (no regex interpretation)
fd -E node_modules -E '*.tmp' patternExclude specific patterns from search
fd --no-ignore patternDon’t use .gitignore, .fdignore, or .ignore files
fd -L patternFollow symbolic links during search
fd --changed-within 2dFiles modified within last 2 days
fd --changed-before 30dFiles not modified in last 30 days
fd --size +100mFiles larger than 100MB
fd --size +10m --size -100mFiles between 10MB and 100MB
fd --owner usernameFiles owned by specific user
fd --max-results 100Limit output to 100 results
fd -x rm {}Execute command on each result (delete files)
fd -X convert {} {.}.pngExecute command with multiple args (batch convert)
fd --color never patternDisable colored output
fd --strip-cwd-prefix patternRemove ./ prefix from results
fd -H -t d "^\."Find hidden directories (starting with dot)
fd -t f -x du -h {}Show file sizes for all matches
fd pattern --threads 1Use single thread (for debugging)
fd --base-directory /path patternChange base directory for search

Configuration

Configuration Files

Global ignore file locations:

  • Linux/macOS: ~/.config/fd/ignore or ~/.fdignore
  • Windows: %APPDATA%\fd\ignore

Project-specific: .fdignore in project root

.fdignore File Example

# Ignore dependency directories
node_modules/
vendor/
target/

# Ignore build outputs
build/
dist/
*.o
*.pyc

# Ignore IDE directories
.idea/
.vscode/
*.swp

# Ignore log files
*.log
logs/

# Ignore temporary files
*.tmp
*~
.DS_Store

# Ignore specific paths
/cache/
/tmp/

Environment Variables

# Set default options for all fd commands
export FD_OPTS="--hidden --follow --exclude .git"

# Control colorization (fd respects LS_COLORS)
export LS_COLORS="di=34:ln=35:ex=31:*.txt=33"

Useful Aliases

# Add to ~/.bashrc or ~/.zshrc

# Search including hidden files
alias fdh='fd -H'

# Search ignoring .gitignore
alias fda='fd -I'

# Find large files
alias fdl='fd --size +100m'

# Find recent files (last 24 hours)
alias fdr='fd --changed-within 1d'

# Find and preview with fzf and bat
alias fdf='fd -t f | fzf --preview "bat --color=always {}"'

# Find and edit with vim
alias fdv='fd -t f | fzf | xargs -r vim'

Common Use Cases

Use Case 1: Clean Build Artifacts

# Remove all Python compiled files
fd -e pyc -e pyo -x rm {}

# Remove all node_modules directories (up to 2 levels deep)
fd -t d -d 2 '^node_modules$' -x rm -rf {}

# Clean old log files (older than 30 days)
fd -e log --changed-before 30d -x rm {}

# Remove all temporary files
fd -g '*.tmp' -g '*~' -g '*.swp' -x rm {}

Use Case 2: Code Search and Analysis

# Find all JavaScript/TypeScript files modified in last week
fd -e js -e ts -e jsx -e tsx --changed-within 7d

# Count lines of code in Rust project
fd -e rs -x wc -l {} | awk '{sum+=$1} END {print sum}'

# Find all TODO comments in Python files
fd -e py -x grep -Hn "TODO:" {}

# Find largest source files
fd -e java -e kt -x du -h {} | sort -hr | head -20

# Find files containing specific function name
fd -e cpp -e hpp -x grep -l "myFunction" {}

Use Case 3: Log File Management

# Find and compress logs older than 7 days
fd -e log --changed-before 7d -x gzip {}

# Search for errors in recent logs
fd -e log --changed-within 1d -x grep -i "error" {} \;

# Find large log files (over 100MB)
fd -e log --size +100m -l

# Archive old logs to separate directory
fd -e log --changed-before 30d -x mv {} /archive/logs/

Use Case 4: Docker and Container Management

# Find all Dockerfiles in project
fd -g '*Dockerfile*' -g 'Dockerfile.*'

# Find all docker-compose files
fd -g 'docker-compose*.yml' -g 'docker-compose*.yaml'

# Find and validate Dockerfiles
fd '^Dockerfile$' -x docker build --dry-run -f {} .

# Find container-related configs
fd -e yml -e yaml -x grep -l "kind:" {} \;

Use Case 5: Security and Permissions Audit

# Find world-writable files (security risk)
fd -t f -x sh -c 'test -w {} && ls -l {}'

# Find SUID/SGID binaries
fd -t x -x sh -c 'test -u {} -o -g {} && ls -l {}'

# Find files with passwords in name
fd -i password -i passwd -i secret

# Find configuration files with potential secrets
fd -g '*.conf' -g '*.cfg' -g '*.ini' -x grep -i "password\|secret\|key" {}

# Find SSH keys
fd -g 'id_rsa*' -g 'id_ed25519*' -H

Best Practices

  • Use .fdignore files: Create project-specific ignore patterns to speed up searches and reduce noise
  • Leverage smart defaults: fd automatically respects .gitignore - use -I only when you need ignored files
  • Combine with other tools: Pipe fd output to xargs, grep, or fzf for powerful workflows
  • Use -0 with xargs: Always use fd -0 | xargs -0 for filenames with spaces or special characters
  • Prefer -x over pipes: Use fd -x command {} instead of piping to xargs for better performance
  • Set depth limits: Use -d flag on large directory trees to prevent excessive recursion
  • Use specific type filters: Filter by type (-t f, -t d) early to reduce search space
  • Create aliases: Set up shell aliases for frequently used fd patterns to save typing
  • Combine time and size filters: Use --changed-within and --size together for precise file targeting
  • Test regex patterns: Use online regex testers before complex fd searches to verify patterns

Troubleshooting

IssueSolution
Command not found: fdOn Debian/Ubuntu, binary is fdfind. Create symlink: ln -s $(which fdfind) ~/.local/bin/fd
Too many resultsUse depth limit -d 3, exclude patterns -E node_modules, or filter by type -t f
Not finding hidden filesAdd -H flag to include hidden files, or -HI to also ignore .gitignore rules
Search is too slowReduce depth with -d, exclude large directories with -E, or use --threads to control parallelism
Regex not matchingRemember fd uses case-insensitive search by default. Use -s for case-sensitive or -F for literal strings
Files in .gitignore showing upThis shouldn’t happen by default. Check for -I or --no-ignore flags in aliases or FD_OPTS
Special characters in filenames breaking commandsUse -0 with xargs -0 or use -x flag instead: fd pattern -x command {}
Cannot execute command on resultsCheck if using correct syntax: -x for individual execution, -X for batch execution
Color output in logs/filesDisable with --color never or redirect stderr: fd pattern 2>/dev/null
Permission denied errorsRedirect stderr to ignore: fd pattern 2>/dev/null or run with appropriate permissions
Not respecting .fdignore fileEnsure .fdignore is in project root or ~/.config/fd/ignore. Check file syntax matches .gitignore format