DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

find(1)


find -- find files

Synopsis

find [path-list] [predicate-list]

Description

find recursively descends the directory hierarchy for each pathname in the path-list (that is, one or more pathnames) seeking files that match a predicate-list, a boolean expression written in the primaries given below.

The default path-list is ``.'' (the current directory).

find processes supplementary code set characters, and recognizes supplementary code set characters in path-list and as described below, according to the locale specified in the LC_CTYPE environment variable (see LANG on environ(5)).

find performs pattern searches on characters, not bytes. In the descriptions, the argument n is used as a decimal integer where +n means more than n, -n means less than n and n means exactly n. Valid expressions in the predicate-list are:


-exit
Always true; causes find to exit immediately with the current exit value. This can be used to preempt the default -print expression.

-name pattern
True if pattern matches the current filename. Normal shell filename generation characters (see sh(1)) may be used. A backslash (\) is used as an escape character within the pattern. The pattern should be escaped or quoted when find is invoked from the shell. pattern may contain supplementary code set characters. Note: a slash (/) can be used in pattern, but it will not match any particular filename.

-perm [-]onum
True if the file permission flags exactly match the octal number onum (see chmod(1)). If onum is prefixed by a minus sign (-), only the bits that are set in onum are compared with the file permission flags, and the expression evaluates true if they match.

-perm [-]mode
The mode argument is used to represent file mode bits. Its format is identical to the chmod symbolic_mode operand and is interpreted in the following manner.

A template is assumed, with all file mode bits cleared. An op symbol of + sets the appropriate mode bits in the template; - clears the appropriate bits; and = sets the appropriate mode bits, without regard to the contents of the process's file mode creation mask. The op symbol of - can't be the first character of mode.

If the hyphen is omitted, the primary evaluates as true when the file permission bits match the value of the resulting template exactly. Otherwise, if mode has a hyphen prefix, the primary evaluates as true if at least all the bits in the resulting template are set in the file permission bits.


-size n[c]
True if the file is n blocks long (512 bytes per block). If n is followed by a c, the size is in bytes.

-atime n
True if the file access time subtracted from the initialization time is n-1 to n multiples of 24 hours. The initialization time is the time between the invocation of the find utility and the first access by that invocation to any file file specified by its path operands.

-mtime n
True if the file modification time subtracted from the initialization time is n-1 to n multiples of 24 hours. The initialization time is the time between the invocation of the find utility and the first access by that invocation to any file file specified by its path operands.

-ctime n
True if the time of last change of file status information subtracted from the initialization time is n-1 to n multiples of 24 hours. The initialization time is the time between the invocation of the find utility and the first access by that invocation to any file file specified by its path operands.

-exec cmd
True if the executed cmd returns a zero value as exit status. A command argument {} is replaced by the current pathname. The end of cmd must be punctuated by an escaped semicolon or a plus sign (+). When a plus sign is used, cmd aggregates a set of pathnames and executes on the set; when a semicolon is used, cmd executes on one pathname at a time. The reason for preferring + to a semicolon is vastly improved performance. cmd may contain supplementary code set characters.

You can prepend the cmd with tfadmin if you need to pass privileges to the cmd. This assumes that an entry for you in the tfadmin database has been previously defined. The super-user will execute the cmd with all privileges; prepending the tfadmin is not necessary in this case.


-ok cmd
Like -exec except that the generated command line is printed with a question mark first. This is a prompt for confirmation. It is executed if the response is affirmative. The form of the affirmative response is locale dependent: ``y'' in the C locale. (See LANG on environ(5).)) cmd may contain supplementary code set characters.

-print
Always true; causes the current pathname to be printed.

-newer file
True if the current file has been modified more recently than the argument file.

-depth
Always true; causes descent of the directory hierarchy to be done so that all entries in a directory are acted on before the directory itself. This can be useful when find is used with cpio(1) to transfer files that are contained in directories without write permission.

-mount
Always true; restricts the search to the file system containing the directory specified.

-local
True if the file physically resides on the local system. This does not restrict the search to only files which physically reside on the local system, it merely matches such files. See ``Examples''.

-xdev [argument list]
True if you restrict your search to the root file system. If you do not specify argument list, the search will be made for every file on local and remote networks.

( expression )
True if the parenthesized expression is true.

-type type
True if the file type corresponds to the specified type:

b
block special file

c
character special file

d
directory

f
regular file

l
symbolic link

p
fifo (named pipe)

s
socket file

-follow
Causes symbolic links to be followed. When following symbolic links, find keeps track of the directories visited so that it can detect infinite loops; for example, such a loop would occur if a symbolic link pointed to an ancestor. This expression should not be used with the -type l expression.

-links n
True if the file has n links.

-user uname
True if the file belongs to the user uname. If uname is numeric and does not appear as a login name in the /etc/passwd file, it is taken as a user ID.

-nouser
True if the file belongs to a user not in the /etc/passwd file.

-group gname
True if the file belongs to the group gname. If gname is numeric and does not appear in the /etc/group file, it is taken as a group ID.

-nogroup
True if the file belongs to a group not in the /etc/group file.

-fstype type
True if the file system to which the file belongs is of type type.

-inum n
True if the file has inode number n.

-prune
Always yields true. Do not examine any directories or files in the directory structure below the expression just matched. See ``Examples''.

The primaries may be combined using the following operators (in order of decreasing precedence):


1.
The negation of a primary (``!'' is the unary not operator).

2.
Concatenation of primaries (the and operation is implied by the juxtaposition of two primaries).

3.
Alternation of primaries (-o is the or operator).
Note that when you use find in conjunction with cpio, if you use the -L option with cpio then you must use the -follow expression with find and vice versa. Otherwise there will be undesirable results.

If no predicate-list is present, -print is used as the expression. Otherwise, if the given expression does not contain any of the primaries -exec, -ok, or -print, the given expression can be replaced by (given_expression) -print. The -user, -group, and -newer primaries each evaluate their respective arguments once.

Files


/etc/passwd

/etc/group

/usr/lib/locale/locale/LC_MESSAGES/uxcore.abi
language-specific message file (See LANG on environ(5).)

Examples

Remove all files in your home directory named a.out or *.o that have not been accessed for a week:

find $HOME \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \;

Recursively print all filenames in the current directory and below, but skipping SCCS directories:

find . -name SCCS -prune -o -print

Recursively print all filenames in the current directory and below, skipping the contents of SCCS directories, but printing out the SCCS directory name:

find . -print -name SCCS -prune

Match only local files, and don't examine the contents of any directory found to be remotely mounted:

find /  ! -local -prune -o -size +50 -print

This only works correctly if there are no local file systems mounted on top of remote directories. This example will print all local files on the system larger than 50 blocks, without wasting time accessing remote files.

To get the same effect, but to check for files in local file systems mounted on remote directories, use:

find / -local -size +50 -print

Exit codes

If find encounters any errors in accessing operands, it returns non-zero.

References

chmod(1), sh(1), stat(2), test(1), umask(2)

Notices

When using find to determine files modified within a range of time, you must use the ?time arguments before the -print argument, or find will return all files.

The following option is obsolete and will not be supported in future releases.


-cpio device
Always true; write the current file on device in cpio(1) format (5120-byte records).

This command has been updated to handle files greater than 2GB.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004