Skip to content

Fd

← Back to all decks

28 cards — 🟢 5 easy | 🟡 10 medium | 🔴 5 hard

🟢 Easy (5)

1. How does fd's default behavior differ from find?

Show answer fd searches recursively with a simpler syntax (no need for . or -name), is case-insensitive by default, respects .gitignore, skips hidden files, and uses colorized output.

Remember: fd = "find for humans." Simpler syntax, .gitignore-aware, parallel, colorized, and 3-5x faster.

2. How do you find only directories (not files) with fd?

Show answer Use the -t d flag: fd -t d "config". Similarly, -t f for files only, -t l for symlinks, -t x for executables, and -t e for empty files/dirs.

Remember: -t d=dirs, -t f=files, -t l=symlinks, -t x=executables, -t e=empty. Composable type flags.

3. How do you search for files by extension with fd?

Show answer Use the -e flag: fd -e yaml finds all YAML files. Combine multiple extensions with: fd -e yaml -e yml.

Example: fd -e py -e js finds Python and JS files. -e handles dotfiles correctly and is more readable than regex.

4. How do you force a case-insensitive search with fd when the pattern contains uppercase letters?

Show answer Use the -i flag: fd -i "README". By default fd is smart-case (case-insensitive unless pattern has uppercase). The -i flag forces case-insensitive regardless.

Under the hood: smart-case — lowercase=insensitive, any uppercase=sensitive. Same as ripgrep. -i forces insensitive.

5. How do you control color output in fd?

Show answer Use --color with never, auto, or always: fd --color never "pattern" disables color (useful when piping to other tools). Default is auto (color for terminals, plain for pipes).

Gotcha: auto mode disables color when piping. Use --color always for pipes (e.g., less -R).

🟡 Medium (10)

1. How do you include hidden files and .gitignore'd files in fd searches?

Show answer Use --hidden to include dotfiles, --no-ignore to include .gitignore'd files, or both flags together to include everything.

Remember: --hidden = show dotfiles. --no-ignore = show gitignored. Both = show everything like find.

2. What is the difference between --exec and --exec-batch in fd?

Show answer --exec runs the command once per match in parallel (like find -exec {} \;). --exec-batch runs the command once with all matches as arguments (like xargs — single process invocation).

Remember: --exec = one cmd per match (parallel). --exec-batch = one cmd with ALL matches (like xargs).

3. How do you filter files by size and modification time with fd?

Show answer Use --size for size (e.g., --size +10m for files over 10MB) and --changed-within or --changed-before for time (e.g., --changed-within 24h for recently modified).

Example: fd --size +10m --changed-within 24h finds large recently-modified files. Great for hunting disk hogs.

4. How do you exclude directories or patterns from fd results?

Show answer Use the -E flag: fd -E node_modules -E .git "config" excludes those directories. Pattern exclusion: fd -E '*.bak' excludes backup files.

Example: fd -E node_modules -E .git 'config' — clean results. Glob patterns: -E '*.bak' excludes backups.

5. How do you limit how deep fd searches into directory trees?

Show answer Use --max-depth (or -d): fd -d 2 "config" searches only the current directory and one level of subdirectories. Useful for avoiding deep node_modules or vendor trees.

Example: fd -d 1 lists only immediate children — equivalent to ls but with regex.

Gotcha: --max-depth 0 means current directory only (files in .), which is rarely useful.

6. How do you safely pipe fd results containing spaces or special characters to xargs?

Show answer Use fd's -0 flag with xargs -0: fd -0 -e log | xargs -0 rm. The -0 flag outputs null-separated paths instead of newline-separated, preventing word-splitting issues.

Remember: Null-separated output prevents word-splitting on filenames with spaces, newlines, or quotes.

Analogy: -0 is the universal safe-pipe flag. ripgrep, fd, xargs, sort, and find all support it.

7. How do you use fd --exec to convert every found .jpg file to .png using a command?

Show answer fd -e jpg --exec convert {} {.}.png. The {} placeholder is the full path and {.} is the path without extension, so each file.jpg becomes file.png.

Under the hood: {.} strips extension (file.jpg → file), so {.}.png → file.png. No shell manipulation needed.

8. How does fd handle .gitignore patterns by default?

Show answer fd respects .gitignore patterns automatically — files ignored by git are excluded from results unless you use --no-ignore or --hidden flags.

Gotcha: fd respects .gitignore even outside git repos. Use --no-ignore to override.

9. How do you execute a command on each fd result?

Show answer Use fd PATTERN --exec COMMAND {} where {} is replaced by each match. For batch execution, use --exec-batch to run the command once with all matches as arguments.

Example: fd -e log --exec gzip {} compresses every log file in parallel. Faster than find -exec on multi-core.

10. How do you search for files by extension using fd?

Show answer Use fd -e EXT (e.g., fd -e py). Multiple extensions: fd -e py -e js. This filters by extension after the pattern match.

Example: fd -e py -e js finds Python and JS files. -e handles dotfiles correctly and is more readable than regex.

🔴 Hard (5)

1. What placeholder tokens are available in fd's --exec command?

Show answer {} = full path, {/} = basename, {//} = parent directory, {.} = path without extension, {/.} = basename without extension.

Remember: {} full path, {/} basename, {//} parent, {.} no extension, {/.} basename no extension.

2. How do you switch fd from regex mode to glob mode?

Show answer Use the -g flag: fd -g '*.yaml' uses glob matching. Use -F for fixed string matching (no regex). Default mode is regex: fd '^test.*\.py$'.

Remember: default=regex, -g=glob, -F=fixed string. Three search modes for different needs.

3. How do you configure project-level ignore rules for fd?

Show answer Create a .fdignore file in the project root with .gitignore syntax. fd also reads .ignore files (shared with rg). Global ignores go in ~/.fdignore.

Analogy: .fdignore is to fd what .gitignore is to git — same glob syntax, same purpose (skip unwanted paths).

Gotcha: fd reads .gitignore AND .fdignore AND .ignore. Use --no-ignore to override all three.

Who made it: David Peter (sharkdp) created fd in 2017 as a Rust rewrite of find.

4. How does fd achieve faster searches than find on large directory trees?

Show answer fd uses multi-threaded directory traversal by default, parallelizing filesystem stat calls. It also skips .gitignore'd paths and hidden directories, reducing total work. Use --threads N to control parallelism.

Under the hood: multi-threaded traversal (--threads N) + .gitignore skipping = 3-5x faster than single-threaded find.

5. Why is fd faster than find for most interactive searches?

Show answer fd uses parallel directory traversal, respects gitignore (skips large dirs like node_modules), and defaults to regex rather than glob — reducing the search space and leveraging multiple cores.

Under the hood: multi-threaded traversal (--threads N) + .gitignore skipping = 3-5x faster than single-threaded find.