find Command Reference for CI Scripts
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 uses expressions rather than flags, and the -exec terminator catches everyone at least once.
Common flags/usage
- -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
Example
shell
find . -name '*.tmp' -type f -delete
find dist -type f -print0 | xargs -0 gzip -9
find "${HOME}/.cache" -type f -mtime +7 -deleteIn CI
"find: missing argument to -exec" means you forgot the escaped \; (or {} +) terminator. "paths must precede expression" means the directory came after a test; put it first. Use -print0 with xargs -0 so filenames with spaces or newlines do not break the pipeline. BSD/macOS find differs from GNU on -mtime and -regex.
Key takeaways
- Every -exec needs a \; or {} + terminator or find errors out.
- Pair -print0 with xargs -0 to handle filenames containing spaces.
- Put the search path before any test expression.
Related guides
xargs Command Reference for CI Scriptsxargs builds and runs commands from stdin in CI. Reference for -0, -n, -P, -I, and -r, plus the empty-input t…
grep Command Reference for CI Scriptsgrep searches text for matching lines in CI. Reference for -r, -E, -i, -q, and -v, plus the exit-code-1-means…
rsync Command Reference for CI Scriptsrsync synchronizes files efficiently in CI deploys and cache restores. Reference for -a, -z, --delete, and th…
rm -rf Command Reference for CI Scriptsrm -rf removes files and directories in CI cleanup. Reference for -r, -f, and safe-deletion habits, plus the…