find
find: search for files in a directory tree.
Synopsis
find [path…] [expression]
Description
find walks the directory tree under each path and prints, one a line, every path that matches all the tests in the expression, the starting point included. With no path, it starts at .; with no tests, it prints everything.
The paths are the arguments before the first one that starts with - or is !. Symbolic links are never followed (as GNU find’s -P): a link is listed as a link, and not walked into.
Expression
All the tests must hold, as if joined by -a.
- -name pattern
- The last part of the path matches the shell pattern (*, ?, […], as sh(1) globs).
- -iname pattern
- Like -name, ignoring case.
- -path pattern
- The whole path, as printed, matches the shell pattern; here * matches / too.
- -type c
- The file is of type c: f a regular file, d a directory, l a symbolic link.
- -not, !
- Turns the next test around.
- -maxdepth n
- Descend at most n levels below the starting points (0: the starting points only). It applies wherever it appears.
- -mindepth n
- Print nothing less than n levels below the starting points.
- Print the path; what find does anyway.
Exit status
0 on success; 1 if a path could not be read, or for a bad expression.
Examples
find /lib -name "*.lua"
find . -type d -maxdepth 2
find /home ! -iname "*.txt"
Notes
There is no -o, no parentheses, and no actions besides -print (no -exec or -delete). A starting point cannot begin with -.
See also
ls(1), du(1), tree(1), grep(1)