find - search for files in a directory hierarchy
| Use Case | Command | Description |
|---|---|---|
| ๐ Find file by name | find . -name "*.txt" | Search for files matching pattern in current directory |
| ๐๏ธ Delete found files | find . -name "*.tmp" -delete | Delete all matching files (use with caution) |
| ๐ Execute command on each file | find . -type f -exec file {} \; | Run file command on each regular file |
| โฐ Find files modified in last 24h | find . -mtime 0 | Files modified less than 24 hours ago |
| ๐ Find files by permission | find . -perm 644 | Files with exact permissions 644 |
| ๐ Find directories only | find . -type d | List all directories |
| ๐ Follow symbolic links | find -L . -name "*.conf" | Follow symlinks while searching |
| ๐ Prune directory | find . -path ./node_modules -prune -o -print | Skip node_modules directory |
| ๐ Find files larger than 100MB | find . -size +100M | Files larger than 100 megabytes |
| ๐ Find broken symlinks | find . -xtype l | Find symbolic links pointing to non-existent files |
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
This manual page documents the GNU version of find. GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name. If no starting-point is specified, . is assumed.
If you are using find in an environment where security is important (for example if you are using it to search directories that are writable by other users), you should read the Security Considerations chapter of the findutils documentation, which is called Finding Files and comes with findutils. That document also includes a lot more detail and discussion than this manual page, so you may find it a more useful source of information.
The -H, -L and -P options control the treatment of symbolic links. Command-line arguments following these are taken to be names of files or directories to be examined, up to the first argument that begins with -, or the argument ( or !. That argument and any following arguments are taken to be the expression describing what is to be searched for. If no paths are given, the current directory is used. If no expression is given, the expression -print is used (but you should probably consider using -print0 instead, anyway).
This manual page talks about 'options' within the expression list. These options control the behaviour of find but are specified immediately after the last path name. The five 'real' options -H, -L, -P, -D and -O must appear before the first path name, if at all. A double dash -- could theoretically be used to signal that any remaining arguments are not options, but this does not really work due to the way find determines the end of the following path arguments: it does that by reading until an expression argument comes (which also starts with a -). Now, if a path argument would start with a -, then find would treat it as expression argument instead. Thus, to ensure that all start points are taken as such, and especially to prevent that wildcard patterns expanded by the calling shell are not mistakenly treated as expression arguments, it is generally safer to prefix wildcards or dubious path names with either ./ or to use absolute path names starting with /.
If more than one of -H, -L and -P is specified, each overrides the others; the last one appearing on the command line takes effect. Since it is the default, the -P option should be considered to be in effect unless either -H or -L is specified.
-D debugopts โ Print diagnostic information. The list of debug options should be comma separated. Valid debug options include:
-Olevel โ Enables query optimisation. The find program reorders tests to speed up execution while preserving the overall effect. The optimisations performed at each optimisation level are as follows:
The part of the command line after the list of starting points is the expression. This is a kind of query specification describing how we match files and what we do with the files that were matched. An expression is composed of a sequence of things:
The -print action is performed on all files for which the whole expression is true, unless it contains an action other than -prune or -quit. Actions which inhibit the default -print are: -delete, -exec, -execdir, -ok, -okdir, -fls, -fprint, -fprintf, -ls, -print and -printf.
Some tests allow comparison between the file currently being examined and some reference file specified on the command line. A numeric argument n can be specified to tests as +n (greater than), -n (less than), or n (exactly).
-amin n โ File was last accessed less than, more than or exactly n minutes ago.-anewer reference โ Time of last access of current file is more recent than last data modification of reference.-atime n โ File was last accessed n*24 hours ago.-cmin n โ File's status was last changed less than, more than or exactly n minutes ago.-cnewer reference โ Time of last status change of current file is more recent than last data modification of reference.-ctime n โ File's status was last changed n*24 hours ago.-empty โ File is empty and is either a regular file or a directory.-executable โ Matches files which are executable and directories which are searchable by the current user.-false โ Always false.-fstype type โ File is on a filesystem of type type.-gid n โ File's numeric group ID is less than, more than or exactly n.-group gname โ File belongs to group gname.-ilname pattern โ Like -lname, but case insensitive.-iname pattern โ Like -name, but case insensitive.-inum n โ File has inode number smaller than, greater than or exactly n.-ipath pattern โ Like -path, but case insensitive.-iregex pattern โ Like -regex, but case insensitive.-iwholename pattern โ See -ipath.-links n โ File has less than, more than or exactly n hard links.-lname pattern โ File is a symbolic link whose contents match shell pattern.-mmin n โ File's data was last modified less than, more than or exactly n minutes ago.-mtime n โ File's data was last modified n*24 hours ago.-name pattern โ Base of file name matches shell pattern. The metacharacters match a leading ..-newer reference โ Time of last data modification of current file is more recent than that of reference.-newerXY reference โ Succeeds if timestamp X of file being considered is newer than timestamp Y of reference. X and Y can be a (access), B (birth), c (status change), m (modification), t (direct time).-nogroup โ No group corresponds to file's numeric group ID.-nouser โ No user corresponds to file's numeric user ID.-path pattern โ File name matches shell pattern. The metacharacters do not treat / or . specially.-perm mode โ File's permission bits are exactly mode (octal or symbolic).-perm -mode โ All of the permission bits mode are set for the file.-perm /mode โ Any of the permission bits mode are set for the file.-readable โ Matches files which are readable by the current user.-regex pattern โ File name matches regular expression. Default is Emacs style.-samefile name โ File refers to the same inode as name.-size n[cwbkMG] โ File uses less than, more than or exactly n units of space, rounding up. Suffixes: b (512-byte blocks), c (bytes), w (2-byte words), k (KiB), M (MiB), G (GiB).-true โ Always true.-type c โ File is of type c: b (block), c (character), d (directory), p (named pipe), f (regular file), l (symbolic link), s (socket), D (door). Multiple types can be comma-separated.-uid n โ File's numeric user ID is less than, more than or exactly n.-used n โ File was last accessed n days after its status was last changed.-user uname โ File is owned by user uname.-wholename pattern โ See -path.-writable โ Matches files which are writable by the current user.-xtype c โ Same as -type unless the file is a symbolic link. For symbolic links, checks the type of the file that -type does not check.-context pattern โ (SELinux only) Security context of the file matches glob.-delete โ Delete files; true if removal succeeded. Implies -depth.-exec command ; โ Execute command; true if 0 status is returned. The string {} is replaced by the current file name. The command is run once per matched file.-exec command {} + โ Variant that builds command line by appending each selected file name at the end. Only one {} allowed, must appear at the end before +.-execdir command ; โ Like -exec but run from the subdirectory containing the matched file.-execdir command {} + โ Like -exec + but from subdirectory.-fls file โ Like -ls but write to file.-fprint file โ Print full file name into file.-fprint0 file โ Like -print0 but write to file.-fprintf file format โ Like -printf but write to file.-ls โ List current file in ls -dils format on standard output.-ok command ; โ Like -exec but ask the user first.-okdir command ; โ Like -execdir but ask the user first.-print โ Print the full file name on standard output, followed by a newline.-print0 โ Print the full file name followed by a null character.-printf format โ Print format on standard output, interpreting \ escapes and % directives. (See man page for full list of directives.)-prune โ If the file is a directory, do not descend into it. Has no effect if -depth is given.-quit โ Exit immediately with return value zero if no errors.Listed in order of decreasing precedence:
( expr ) โ Force precedence (parentheses must be quoted).! expr or -not expr โ True if expr is false.expr1 expr2 โ Implied -a (AND).expr1 -a expr2 โ AND.expr1 -o expr2 โ OR.expr1 , expr2 โ List; both evaluated, value of expr2 is returned.find exits with status 0 if all files are processed successfully, greater than 0 if errors occur. If the return value is non-zero, you should not rely on the correctness of the results. When some error occurs, find may stop immediately without completing all specified actions.
$ find /tmp -name core -type f -print | xargs /bin/rm -f
Find files named core in or below /tmp and delete them. Note: This will work incorrectly if filenames contain newlines, quotes, or spaces.
$ find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
Safer version that handles filenames containing special characters.
$ find . -type f -exec file '{}' \;
Run file on every regular file in or below the current directory.
$ find / \
\( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
List set-user-ID files into /root/suid.txt and large files into /root/big.txt in one traversal.
$ find $HOME -mtime 0
Search for files in your home directory modified in the last twenty-four hours.
$ find /sbin /usr/sbin -executable \! -readable -print
$ find . -perm 664
$ find . -perm -664
$ find . -perm /222
$ find . -perm /220
$ find . -perm -220
$ find . -perm -444 -perm /222 \! -perm /111
Various permission searches: executable but not readable, exact permissions, all bits set, any bit set, etc.
$ cd /source-dir
$ find . -name .snapshot -prune -o \( \! -name '*~' -print0 \) \
| cpio -pmd0 /dest-dir
Copy /source-dir to /dest-dir omitting .snapshot directories and files ending in ~.
$ find repo/ \
\( -exec test -d '{}/.svn' \; \
-or -exec test -d '{}/.git' \; \
-or -exec test -d '{}/CVS' \; \
\) -print -prune
Efficiently find SCM roots (with -prune to avoid unnecessary descent).
$ find /tmp -type f,d,l
$ find / \( -type f -o -type d -o -type l \)
$ find / -name needle -print -quit
$ find . .. / /tmp /tmp/TRACE compile compile/64/tests/find -maxdepth 0 -printf '[%h][%f]\n'
Search for multiple file types, stop after finding first match, demonstrate %h and %f format directives.
chmod(1), locate(1), ls(1), updatedb(1), xargs(1), lstat(2), stat(2), ctime(3), fnmatch(3), printf(3), strftime(3), locatedb(5), regex(7)
Full documentation: https://www.gnu.org/software/findutils/find or available locally via: info find
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-14 13:19 @216.73.216.174
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)