Skip to content
Latchkey

fd: -e Extension Filters and -x Exec

fd -e <ext> matches files by extension and fd -x <cmd> runs that command once per matched file, in parallel.

The -x flag turns fd into a parallel find -exec, which is handy for formatting or linting every file of a type. The {} placeholders mirror parallel.

What it does

fd -e ext keeps only files with that extension (repeatable). -x cmd runs cmd once per result, in parallel across CPU cores; -X cmd runs it once with all results appended (like xargs). Inside the command, {} is the path, {/} the basename, {.} the path without extension, {//} the parent.

Common usage

Terminal
fd -e js -e ts                       # JS or TS files
fd -e py -x black {}                 # format each Python file (parallel)
fd -e svg -X svgo                    # one svgo call with all SVGs
fd -e png -x sh -c 'identify "{}"'   # run a shell snippet per file
fd '' -e log -x rm                   # delete every .log file

Options

FlagWhat it does
-e / --extension <ext>Filter by extension (no leading dot); repeatable
-x / --exec <cmd>Run cmd once per result, in parallel
-X / --exec-batch <cmd>Run cmd once with all results as arguments
{}Placeholder for the full path
{/} {.} {//} {/.}Basename, no-extension, parent, basename-no-ext
-j / --threads <n>Limit the number of parallel jobs

In CI

Prefer -X for tools that accept many paths (prettier, eslint) since one process is faster than thousands; use -x for per-file tools or when you need a fresh process each time. fd -x does not stop on the first non-zero exit, so a formatting step can succeed even if one file failed; check explicitly if that matters.

Common errors in CI

If {} appears literally in the executed command, you quoted it so the shell stripped meaning, or you forgot it entirely and fd appended the path. "command not found" inside -x refers to the tool you are invoking, not fd. With -X on a huge file set you can still hit the OS argument limit; switch to -x (per file) in that case.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →