find(1) find(1)
NAME
find - scan directories for files
SYNOPSIS
find directory ... expression
DESCRIPTION
find scans directories and all their subdirectories for files which
match a specified search criterion. Files located in this way can be
listed and/or processed with a command.
find locates not only ordinary files, but also directories, special
files and FIFOs.
OPTIONS
directory
Name of the directory that is to be scanned. find will search
through this directory and recursively through its subdirec-
tories, provided you have read and execute permission (r and x
bit) for them. More than one directory may be named.
expression
expression may be given as one or more primary expressions (pri-
maries) of the kind listed below or as a combination of these
primaries.
find applies expression to each file in the specified directories
or subdirectories by evaluating primaries from left to right.
Each primary is considered to have a "true" or "false" value for
a file. The truth value of each expression and the next rela-
tional operator determine whether or not find will process the
next primary.
Most primaries define conditions, i.e. they return a value of
true if the current file satisfies the condition. The expres-
sions:
-print
-exec command \;
-ok command \;
-cpio device
are not conditions. They cause actions to be executed, e.g. out-
put of the file name or deletion of the file. When find processes
one of these expressions, the associated action is always per-
formed, regardless of whether the expression returns a value of
true or false. If none of the above action primaries are speci-
fied, -print is executed by default.
Shell metacharacters that appear in expression must be escaped to
ensure that they are passed to find and not interpreted by the
shell.
Page 1 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
The following section describes primaries; the method of combin-
ing primaries is shown thereafter.
Primaries as conditions
If you use options to find files with specific attributes (e.g. the
files modified within a given period), the relevant option must come
before the -print option (see below), as otherwise all files will be
listed.
In the following discussion, n represents a decimal integer; +n means
"more than n", -n means "less than n", and n means "exactly n".
-name pattern
True if pattern matches the name of the current file.
You can also use the usual shell metanotation for file name gen-
eration, but then pattern must be enclosed in single quotes, e.g.
find /usr/adam -name 'group.*' [see specialchar(5)]. Only file
basenames may be specified; pathnames such as text/tmp are not
permitted.
-perm mode
True if the permissions for the current file are those described
by mode (see chmod, Symbolic form). To compare the permissions,
find generates a template without file permission bits and modi-
fies it in accordance with the specifications for mode. If mode
is prefixed by a minus sign, only the bits described in mode are
compared with the permissions, and the expression evaluates true
if they match.
In order to avoid incorrect interpretations, mode itself must not
begin with -, i.e. you must always specify explicitly who you
want to withdraw permissions from.
-perm onum
True if the file permission flags exactly match the octal number
onum (see chmod). If onum is prefixed by a minus sign (-), only
the bits that are set in onum are compared with the file permis-
sion flags, and the expression evaluates true if they match.
Page 2 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
-type character
True if the current file is of type character, where character
can be:
f ordinary file
d directory
b block special file
c character special file
l symbolic links
p named pipe or FIFO file
-fstype name
True if the file system to which the current file belongs is of
type name, where name can be any of the following:
hs, nfs, ufs or vxfs (and also some special file systems such as
proc or fdfs).
-links [±]n
True if there are (more/less than) n links to the current file.
-inum [±]n
True if the current file has an inode number greater than (+),
less than (-), or equal to n. The expression -inum +n -inum -m
can be used to find all inode numbers between n and m.
-user loginname
True if the current file is owned by the user loginname.
-nouser
True if the current file belongs to a user whose login name does
not appear in the /etc/passwd file.
-group groupname
True if the current file belongs to the group groupname.
-nogroup
True if the current file belongs to a group that is not listed in
the /etc/group file.
Page 3 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
-size [±]n[c]
c not specified:
True if the current file is (more/less than) n blocks long, where
one block is 512 bytes.
c specified:
True if the current file is (more/less than) n bytes long.
-atime [±]n
(access time) True if the current file was last accessed
(more/less than) n * 24 hours ago. The access time of directories
searched by find is changed by find itself.
-mtime [±]n
(modification time) True if the current file was last modified
(more/less than) n * 24 hours ago.
-ctime [±]n
True if the inode of the current file was last modified
(more/less than) n * 24 hours ago.
-newer file
True if the current file is "newer" than the specified file, i.e.
if it was created or modified at a later point in time.
-local
True if the current file physically resides on the local system.
-prune
Always yields true. Do not examine any directories or files in
the directory structure below the pattern just matched. See -name
pattern and Example 5 and 6, below.
If -depth is specified, -prune will have no effect.
Page 4 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
Action primaries
-print
Always true. If this expression is present, it causes find to
print the path name of the current file on standard output.
-exec command \;
command is executed as soon as this expression is processed.
You must terminate command with a blank and an escaped semicolon
(\;). A set of braces {} can be used to represent the name of the
current file.
The expression -exec command \; is true if the executed command
returns an exit status of 0. The truth value is significant when
this expression is combined with other expressions.
-ok command \;
Like -exec, except that find asks if the command is to be exe-
cuted each time the expression is processed. The command is only
executed if you respond with the character or string signifying
"yes" in the current locale (see environment variable LANG).
-cpio device
Always true. On processing this expression, find prints the con-
tents of the specified file in cpio format on the specified
device (see cpio).
This option is obsolete and will not be supported in future
releases.
Expressions that affect the behavior of find
-depth
Always true. If present, this expression causes find to act upon
entries in a directory before the directory itself. This can be
useful if find is used with the cpio command to transfer files
contained in directories for which you have no write permission.
-follow
Always true. This expression causes symbolic links to be fol-
lowed. It should not be combined with the -type l expression.
Note that when you use find in conjunction with cpio, if you use
the -L option with cpio you must use the -follow expression with
find, and vice versa. Otherwise, there will be undesirable results.
-mount
Always true. If this expression is present, it causes find to
restrict its search to the file system containing the directory
specified.
Page 5 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
-nonfs
If this option is set, find does not go into directories that
have been mounted with NFS. If find is started with this option
in an NFS directory, it ends without performing any action.
-xdev
Like -mount.
Combining expressions
The expressions described above can be combined with one another as
shown below. Please note the blanks used before and after the opera-
tors!
The operators are listed in order of decreasing precedence.
\( expression... \)
Parentheses group expressions together. The parentheses them-
selves must be escaped with a backslash, since they have a spe-
cial meaning for the shell.
! expression
Negation, i.e. true if the expression evaluates to false.
expression expression or expression -a expression
Logical AND, i.e. true if both expressions are true. If the first
expression is false, find does not process the second expression.
Example:
If the second expression is
-exec command \;
the specified command will only be executed if the first expres-
sion is true.
expression -o expression
Logical OR, i.e. true when either of the expressions is true. If
the first expression is true, find does not process the second
expression.
Example:
If the second expression is
-exec command \;
the command will only be executed if the first expression is
false.
Page 6 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
DIAGNOSTICS
Error messages without command termination (non-zero exit status)
find: Cannot read dir dir: Permission denied
Since you have no read permission for the dir directory, this direc-
tory cannot be scanned. find does not terminate after this error mes-
sage, but continues scanning directories for which you do have the
required access permissions (r bit).
find: Cannot access dir/file: Permission denied
Since you have no execute permission (x bit) for dir, this directory
cannot be scanned. find does not terminate after this message but
searches through those directories for which you do have the appropri-
ate permissions (r and x bits).
Error messages without command termination (exit status 0)
find: error while searching through/below dir: No such file or directory
There is no directory named dir.
Error messages with command termination (non-zero exit status)
find: missing conjunction
You have either combined primaries incorrectly in the find call or
specified more than one argument in a primary.
find: no action specified
You have not specified an action (print, exec, ok, cpio).
find: incomplete statement
You have forgotten the escaped semicolon \; which is required to ter-
minate a command in an -exec or -ok expression.
find: insufficient number of arguments
You have specified too few arguments.
find: path-list predicate-list
You have failed to specify the pathname list for directory.
Page 7 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
EXAMPLES
Example 1
A simple example to illustrate how find works:
Display the path names of all files that
- are located in the current directory or in a subdirectory and
- have the name tmp.
$ find . -name tmp -print
In this case, expression comprises two primaries that are linked by a
logical AND operator. find first checks the -name tmp primary for each
file. If this expression is true (i.e. the current file is named tmp),
find will also process the expression -print, which outputs the path
names. Otherwise, find does not process the -print expression and
remains silent.
Please note the sequence. If you entered:
$ find . -print -name tmp
instead, find would process the -print expression for each file, i.e.
would output the path names of all files.
Example 2
A more complex example:
Display the path names of all files that
- are located in the current directory or its subdirectories, and
- are named tmp or have names ending in .xx.
$ find . \( -name tmp -o -name '*.xx' \) -print
Please note the use of blanks between the arguments!
find begins by processing the parenthesized specifications for each
file. These comprise two primaries linked by a logical OR operator.
find first tests the -name tmp primary. If this expression is true
(i.e. if the current file is named tmp), find does not process the
expression -name '*.xx' at all; this is because the result of the
expression in parentheses will be true in any case. If -name tmp
evaluates to false, find tests the second primary, i.e. -name '*.xx'.
If this expression is true (i.e. the file name ends in .xx), the
parenthesized expression will also evaluate to true; otherwise, the
result of the expression in parentheses is false.
Page 8 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
If the parenthesized expression is true, find then processes the
-print expression, i.e. outputs the file names (AND operator; see
Example 1). If false, find does not process the -print expression,
i.e. remains silent.
Example 3
Search all entries in the /usr/santaclaus directory and its subdirec-
tories and print the files not owned by santaclaus.
$ find /usr/santaclaus ! -user santaclaus -print
Example 4
Delete all files that
- are named tmp or have names ending in .xx, and
- have not been accessed for more than 7 days.
Confirmation is to be requested before the removal of each file.
$ find / \( -name tmp -o -name '*.xx' \) -atime +7 -ok rm {} \;
Example 5
Recursively print all file names in the current directory and below,
but skipping all SCCS directories:
$ find . -name SCCS -prune -o -print
Example 6
Recursively print all file names in the current directory and below,
skipping the contents of SCCS directories, but printing out the SCCS
directory name:
find . -print -name SCCS -prune
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed.
In file name generation patterns in square brackets (such as find .
-name [[=a=]]* -print), the LCCOLLATE environment variable governs
the scope of character ranges, equivalence classes and collating ele-
ments, and the LCTYPE environment variable governs the scope of char-
acter classes.
If LCMESSAGES, LCCOLLATE or LCCTYPE is undefined or is defined as
the null string, it defaults to the value of LANG. If LANG is likewise
undefined or null, the system acts as if it were not internationalized.
Page 9 Reliant UNIX 5.44 Printed 11/98
find(1) find(1)
If any of the locale variables has an invalid value, the system acts
as if none of the variables were set.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
FILES
/etc/group
File containing group names
/etc/passwd
File containing login names
SEE ALSO
chmod(1), cpio(1), ln(1), sh(1), test(1), stat(2), fs(4).
Page 10 Reliant UNIX 5.44 Printed 11/98