find Command Reference

All find predicates, tests and actions with types and logical operators.

Reference for GNU/BSD find command predicates — name, type, mtime, size, perm and owner tests — plus actions (print0, exec, delete, prune), logical operators and global options like -L and -maxdepth, each with an example.

What does the n in -mtime n really mean?

It counts 24-hour periods. -mtime n matches files modified exactly n days ago, +n matches more than n days ago, and -n matches less than n days ago. Use -mmin for minute-level granularity instead of days.

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/-iname and -path match by glob, -type by file kind, -mtime/-mmin and friends by timestamp, -size by bytes or blocks, and -perm, -user, -group by metadata.
  • Operators combine tests. Adjacent tests imply AND; -o is 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, -print0 makes it pipe-safe, -exec runs a command, and -delete removes the file.
  • Global options such as -L (follow symlinks), -maxdepth/-mindepth and -xdev shape 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.