Overview
Give find a starting directory followed by tests. A dot means the current directory. Combining tests lets you select a file by both its type and its name.
Background
A simple find command appeared in Version 1 Unix and was removed in Version 3. It was rewritten for Version 5 and later enhanced for the Programmer's Workbench, according to the FreeBSD and macOS manuals. Today the name covers separate programs: GNU find from the findutils package, the find that macOS ships, and the find applet in BusyBox. They agree on starting paths, -name and -type, and differ on traversal limits, time units, and extra tests.
Examples
Find regular files whose names end in .log:
find . -type f -name '*.log'
Find directories named cache:
find . -type d -name 'cache'
Match a name regardless of letter case:
find . -type f -iname '*.LOG'
Exclude files that match a name:
find . -type f ! -name '*.log'
Match either of two names; the parentheses group the alternatives and must be escaped from the shell:
find . -type f \( -name '*.log' -o -name '*.txt' \)
Find files modified within the last 7 days:
find . -type f -mtime -7
List every directory below the starting point:
find . -type d
Run a read-only command on each match, passing many files per invocation:
find . -type f -name '*.log' -exec grep -l 'ERROR' {} +
Options
-name
Match the filename against a pattern. Quote a wildcard pattern so find, rather than your shell,
expands it.
-type
Restrict results by type. Use f for regular files and d for directories.
-iname
Like -name, but ignores letter case.
-o
Match when either side is true. -o binds more loosely than the implied "and" between tests, so group
alternatives with escaped parentheses.
-mtime
Match by modification time in whole days. -mtime -7 means less than 7 days ago, -mtime +7 means more
than 7 days ago.
-exec
Run a command for each match. Ending the command with {} + passes many files at once; ending with \;
runs it once per file. Try a read-only command first, because -exec can run anything, including
deletes.
Common mistakes
Always include a starting directory for portable commands. find . -name '*.log' differs from leaving the wildcard unquoted. Filenames can contain spaces or newlines, so do not split find output on whitespace to pass it to another tool.
Portability
Actions that delete files need special care and are not used here; the one -exec example runs a read-only command. The Common examples were executed on GNU findutils 4.10.0, macOS find, and BusyBox 1.37.0 (see the development guide for the exact check). Features such as traversal limits, time units, and regex matching differ between implementations and versions.
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.