Skip to content
Latchkey

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 -delete

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →