Glossary

find

find is the Unix tool for locating files by any criterion you care to name: filename, path, type, size, modification time, ownership, permissions, or arbitrary logical combinations thereof. It walks a directory tree starting at one or more paths, testing each file against your expression.

find .                                  # all files under .
find . -name "*.txt"                    # by name
find . -iname "*.JPG" -o -iname "*.png" # case insensitive, or
find / -type f -size +100M              # files over 100 MB
find /var/log -mtime -1                 # modified in last day
find . -type d -empty                   # empty directories
find . -user alice -perm -0644          # owned by alice, at least rw-r--r--
find . -name "*.tmp" -delete            # delete matches (careful!)
find . -name "*.log" -exec gzip {} +    # run a command on matches

The expression language is rich: tests (-name, -type, -size), actions (-print, -delete, -exec), and operators (-and, -or, -not, parentheses). The default action is -print.

find differs from locate in that it scans the filesystem live, so it is always up to date but slow on large trees. For real-time search, find is the gold standard; for quick repetitive queries, locate's prebuilt database is handier.

Related terms: locate, xargs, grep

Discussed in:

Also defined in: Textbook of Linux