man > find(1)

๐Ÿ“– NAME

find - search for files in a directory hierarchy

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ” Find file by namefind . -name "*.txt"Search for files matching pattern in current directory
๐Ÿ—‘๏ธ Delete found filesfind . -name "*.tmp" -deleteDelete all matching files (use with caution)
๐Ÿ“„ Execute command on each filefind . -type f -exec file {} \;Run file command on each regular file
โฐ Find files modified in last 24hfind . -mtime 0Files modified less than 24 hours ago
๐Ÿ”’ Find files by permissionfind . -perm 644Files with exact permissions 644
๐Ÿ“‚ Find directories onlyfind . -type dList all directories
๐Ÿ”— Follow symbolic linksfind -L . -name "*.conf"Follow symlinks while searching
๐Ÿ›‘ Prune directoryfind . -path ./node_modules -prune -o -printSkip node_modules directory
๐Ÿ“ Find files larger than 100MBfind . -size +100MFiles larger than 100 megabytes
๐Ÿ”— Find broken symlinksfind . -xtype lFind symbolic links pointing to non-existent files

๐Ÿ“‹ SYNOPSIS

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]

๐Ÿ“ DESCRIPTION

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.

โš™๏ธ OPTIONS

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 /.

๐Ÿ”— Symbolic Link Handling

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.

๐Ÿ› Debug Options

-D debugopts โ€” Print diagnostic information. The list of debug options should be comma separated. Valid debug options include:

โšก Optimisation Level

-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:

๐Ÿ“ EXPRESSION

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.

๐Ÿ“ Positional Options

๐ŸŒ Global Options

๐Ÿงช Tests

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).

โšก Actions

๐Ÿ”— Operators

Listed in order of decreasing precedence:

๐Ÿšช Exit Codes

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.

๐Ÿ–ฅ๏ธ Examples

๐Ÿ” Simple `find|xargs` approach

$ 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.

๐Ÿ”’ Safer `find -print0 | xargs -0` approach

$ find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

Safer version that handles filenames containing special characters.

โšก Executing a command for each file

$ find . -type f -exec file '{}' \;

Run file on every regular file in or below the current directory.

๐Ÿ“‚ Traversing the filesystem just once for 2 different actions

$ 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.

โฐ Searching files by age

$ find $HOME -mtime 0

Search for files in your home directory modified in the last twenty-four hours.

๐Ÿ”’ Searching files by permissions

$ 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.

๐Ÿ›‘ Pruning โ€” omitting files and subdirectories

$ 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).

๐Ÿ“š Other useful examples

$ 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.

๐Ÿ“š SEE ALSO

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

find(1)
๐Ÿ“– NAME ๐Ÿš€ Quick Reference ๐Ÿ“‹ SYNOPSIS ๐Ÿ“ DESCRIPTION โš™๏ธ OPTIONS
๐Ÿ”— Symbolic Link Handling ๐Ÿ› Debug Options โšก Optimisation Level
๐Ÿ“ EXPRESSION
๐Ÿ“ Positional Options ๐ŸŒ Global Options ๐Ÿงช Tests โšก Actions ๐Ÿ”— Operators
๐Ÿšช Exit Codes ๐Ÿ–ฅ๏ธ Examples
๐Ÿ” Simple `find|xargs` approach ๐Ÿ”’ Safer `find -print0 | xargs -0` approach โšก Executing a command for each file ๐Ÿ“‚ Traversing the filesystem just once for 2 different actions โฐ Searching files by age ๐Ÿ”’ Searching files by permissions ๐Ÿ›‘ Pruning โ€” omitting files and subdirectories ๐Ÿ“š Other useful examples
๐Ÿ“š SEE ALSO

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)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^