find
find walks a directory tree and evaluates an expression against every file it encounters. The expression is built from tests (predicates that match by name, type, time, size, permission or owner), actions (what to do with a match, like print or delete), and logical operators that combine them. This page is a searchable, offline reference to find’s predicates, actions, operators and global options, each with a working example.
How it works
A find command has the shape find [options] [paths] [expression]. For each file
in the tree, find evaluates the expression left to right:
- Tests return true or false:
-name/-inameand-pathmatch by glob,-typeby file kind,-mtime/-mminand friends by timestamp,-sizeby bytes or blocks, and-perm,-user,-groupby metadata. - Operators combine tests. Adjacent tests imply AND;
-ois OR;!negates;\( \)groups to control precedence. AND binds tighter than OR. - Actions run when the preceding tests are true.
-print(the default) shows the path,-print0makes it pipe-safe,-execruns a command, and-deleteremoves the file. - Global options such as
-L(follow symlinks),-maxdepth/-mindepthand-xdevshape the traversal itself and apply to the whole command.
Because the expression is evaluated lazily, ordering matters: cheap tests like
-type f should come before expensive ones like -name over many files, and an
action only runs if every preceding test in its AND chain passed.
Tips and examples
Find and delete files older than 30 days under a cache directory:
find /var/cache/app -type f -mtime +30 -delete
Search inside only C and header files for a pattern, batching efficiently:
find src -type f \( -name '*.c' -o -name '*.h' \) -exec grep -n TODO {} +
Skip a heavy subtree while listing everything else:
find . -name node_modules -prune -o -type f -print
Handle tricky filenames safely through a pipe:
find . -name '*.jpg' -print0 | xargs -0 -n1 identify
When in doubt, run the command with -print first to preview the matches before
attaching a destructive action like -delete or -exec rm.