find

NAME

find - walk a file hierarchy

SYNOPSIS

find [-L|-P] [-DdHhiXx] [-level num] [-f file] file  [file ...] [expression] 

DESCRIPTION

The find(1) utility recursively descends the directory tree for each file listed, evaluating an expression (composed of the primaries and operands listed below) in terms of each file in the tree.

OPTIONS

-d
Performs a depth-first traversal; that is, directories are visited in post-order, and all entries in a directory are acted upon before the directory itself. By default, find(1) visits directories in pre-order; that is, before their contents. Note: the default is not a breadth-first traversal.
-D
Always display domain name in long formats. The default is to display the domain name only if it is different from the value of the environment variable USERDOMAIN, normally the current domain.
-f
Specifies the file hierarchy for find(1) to traverse. File hierarchies can also be specified as the operands immediately following the options.
-h
Causes find(1) to return information about files referenced by symbolic links rather than about the links themselves. If the referenced file does not exist, the information is for the link, not the file.
-H
Follows symbolic links in tree traversal.
-i
Ignores case in file names for the -name and -path directives. This is useful when dealing with some networked files systems with Windows.
-L
Same as -h.
-P
Causes find(1) to return information about files referenced by symbolic links rather than about the links themselves. If the referenced file does not exist, the information is for the link, not the file. File information of all symbolic links not on the command line pertains to the link itself.
-x
Prevents find(1) from descending into directories that have a device number that differs from that of the file from which the descent began.
-X
Warns of file names containing delimiting characters used by xargs(1). If a file name contains any of the delimiting characters used by xargs(1), find(1) displays a diagnostic message on standard error and skips the file. Delimiting characters include single quotes ( ' ), double quotes ( " ), backslash (\), space, tab and newline characters.

PRIMARIES

-atime n
True if the difference between the file last access time and the time find(1) was started, rounded up to the next full 24-hour period, is n 24-hour periods.
-ctime n
True if the difference between the time of last change of file status information and the time find(1) was started, rounded up to the next full 24-hour period, is n 24-hour periods.
-depth
Same as the -d option.
-empty
True if the current file or directory is empty.
-exec utility argument ... ;
True if the program named utility returns a zero value as its exit status. Optional arguments can be passed to the utility. The expression must be terminated by a semicolon (;). If the string {} appears anywhere in the utility name or the arguments, it is replaced by the path name of the current file. Because the semicolon (;) has special meaning to the shell, it must be escaped or quoted. Utility will be executed from the directory from which find(1) was executed.
-execdir utility argument ... ;
Identical to -exec, except that the utility is executed from the directory that holds the current file. The file name substituted for "{}" is not qualified.
-follow
Same as the -H option.
-fstype type
True if the file is contained in a file system of type type. Currently supported types are local, mfs, nfs, msdos, rdonly, and ufs. The types local and rdonly are not specific file-system types. The former matches any file system physically mounted on the system where the find(1) is being executed, and the latter matches any file system that is mounted read-only.
-group gname
True if the file belongs to the group gname. If gname is numeric and there is no such group name, gname is treated as a group id.
-icase
Always true; causes case-insensitive matching for -name and -path, similar to the -i option.
-inum n
True if the file has file serial number n.
-links n
True if the file has n links.
-ls
This primary always evaluates to true. The following information for the current file is written to standard output: its file serial number, size in 512-byte blocks, file permissions, number of hard links, owner, group, size in bytes, last modification time, and path name. If the file is a block or character special file, the major and minor numbers will be displayed instead of the size in bytes. If the file is a symbolic link, the path name of the linked-to file will be displayed preceded by ->. The format is identical to that produced by ls -dgils.
-maxdepth n
True if the search depth is at least the value specified in n. The search will go only that deep, relative to the starting directory.
-mount
Prevents find(1) from descending into directories whose device number differs from that of the file from which the descent began. See the -x option.
-mtime n
True if the difference between the file last modification time and the time find(1) was started, rounded up to the next full 24-hour period, is n 24-hour periods.
-ok utility argument ... ;
The -ok primary is identical to the -exec primary with the exception that find(1) requests user affirmation for the execution of the utility by printing a message to the terminal and reading a response. If the response is other than y the command is not executed and the value of the ok expression is false.
-name pattern
True if the last component of the path name being examined matches pattern. Special shell-pattern matching characters ([, ], *, and ?) can be used as part of pattern. These characters can be matched explicitly by escaping them with a backslash (\). The pattern should be quoted or escaped to prevent the shell from evaluating it; see the section entitled Examples.
-newer file
True if the current file has a more recent last modification time than file.
-nouser
True if the file belongs to an unknown user.
-nogroup
True if the file belongs to an unknown group.
-path pattern
True if the path name being examined matches pattern. Special shell-pattern matching characters ([, ], *, and ?) can be used as part of pattern. These characters can be matched explicitly by escaping them with a backslash (\). Forward slashes (/) are treated as normal characters and need not be matched explicitly.
-perm mode
The mode may be either symbolic (see chmod(1)) or an octal number. If the mode is symbolic, a starting value of zero is assumed and the mode sets or clears permissions without regard to the file mode creation mask of the process. If the mode is octal, only bits 07777 (S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO) of the file's mode bits participate in the comparison. If the mode is preceded by a dash (-), this primary evaluates to true if at least all of the bits in the mode are set in the file's mode bits. If the mode is not preceded by a dash, this primary evaluates to true if the bits in the mode exactly match the file's mode bits. Note that the first character of a symbolic mode cannot be a dash (-).
-print
This primary always evaluates to true. It prints the path name of the current file to standard output. The expression is appended to the user specified expression if neither -exec, -ls or -ok is specified.
-print0
This primary always evaluates to true. It prints the path name of the current file to standard output, followed by a null character.
-prune
This primary always evaluates to true. It causes find(1) not to descend into the current file. The -prune primary has no effect if the -d option was specified.
-size n[c]
True if the file's size, rounded up, in 512-byte blocks is n. If n is followed by a c, then the primary is true if the file's size is n bytes.
-type t
True if the file is of the specified type. Possible file types are as follows:
b
Block special
c
Character special
d
Directory
f
Regular file
l
Symlink
p
FIFO
s
Socket
-user uname
True if the file belongs to the user uname. If uname is numeric and there is no such user name, uname is treated as a user id.
-xdev
Same as -mount.

All primaries that take a numeric argument allow the number to be preceded by a plus sign (+) or a minus sign (-). A preceding plus sign means more than n, a preceding minus sign means less than n, and if neither is present, it means exactly n.

OPERATORS

The primaries may be combined using the following operators. The operators are listed in order of decreasing precedence.

-level num
Only descend num levels in the directory hierachy.
!expression
This is the unary NOT operator. It evaluates to true if the expression is false. Because the exclamation mark (!) might have special meaning to your shell, you may need to escape or quote it in some manner.
(expression)
This evaluates to true if the parenthesized expression evaluates to true. Because parentheses have special meaning to the shell, they must be escaped or quoted in some manner.
expression -and expression
The -and operator is the logical AND operator. Because it is implied by the juxtaposition of two expressions, it need not be specified. The expression evaluates to true if both expressions are true. The second expression is not evaluated if the first expression is false. It can be shortened to -a.
expression -or expression
The -or operator is the logical OR operator. The expression evaluates to true if either the first or the second expression is true. The second expression is not evaluated if the first expression is true. The operator can be shortened to -o.

All operands and primaries must be separate arguments to find(1). Primaries which themselves take arguments expect each argument to be a separate argument to find(1).

DIAGNOSTICS

Find(1) returns 0 if all instances of path were successfully traversed, and >0 otherwise.

EXAMPLES

The following examples are shown as given to the shell:

Print out a list of all the files whose names do not end in .c.

find  /  \!  -name  *.c  -print

Print out a list of all the files whose names do not end in .c or .h.

find  /  \!  \( -name  *.c -a -name *.h \) -print

Print out a list of all the files owned by user "wnj" that are newer than the file ttt.

find  /  -newer  ttt  -user  wnj  -print

Print out a list of all the files which are not both newer than ttt and owned by "wnj".

find  /  \!  \(  -newer  ttt  -user  wnj  \)  -print

Print out a list of all the files that are either owned by "wnj" or that are newer than ttt.

find  /  \(  -newer  ttt  -or  -user wnj  \)  -print

Copy all files older than ttt to /tmp.

find / \! -newer ttt -exec cp {} /tmp ";"

SEE ALSO

xargs(1)