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
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' -printOptions
| Expression | What it does |
|---|---|
| -name / -iname | Match (case-insensitive) by glob |
| -type f|d|l | File, directory, or symlink |
| -mtime / -size | Filter by age / size |
| -exec cmd {} \; | Run cmd per match (\+ batches them) |
| -print0 | Null-delimited output for xargs -0 |
| -prune | Skip 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.