Skip to content
Latchkey

find: Usage, Options & Common CI Errors

find recursively locates files by name, type, time, or size and can run a command on each.

find drives cleanup, batch processing, and cache pruning in pipelines. Its syntax is unusual (expressions, not flags), and the -exec terminator catches everyone at least once.

What it does

find descends a directory tree, evaluates an expression of tests (name, type, mtime, size) against each entry, and performs actions (-print, -delete, -exec) on matches.

Common usage

Terminal
find . -name '*.log' -type f
find . -name '*.tmp' -delete
find . -type f -mtime +7              # older than 7 days
find . -name '*.js' -exec gzip {} \;  # run per file
find . -type f -print0 | xargs -0 rm  # safe for spaces
find build -type d -name node_modules -prune -o -name '*.map' -print

Options

ExpressionWhat it does
-name / -inameMatch (case-insensitive) by glob
-type f|d|lFile, directory, or symlink
-mtime / -sizeFilter by age / size
-exec cmd {} \;Run cmd per match (\+ batches them)
-print0Null-delimited output for xargs -0
-pruneSkip a directory subtree

Common errors in CI

find: missing argument to -exec - the -exec must end with an escaped \; (or {} +). "find: paths must precede expression" means the path came after a test (put the directory first). On BSD/macOS, -mtime/-name semantics and -regex differ from GNU find. Use -print0 with xargs -0 so filenames with spaces or newlines do not break the pipeline.

Related guides

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