NAME
FIND - Finds files matching an expression.
SYNTAX
find pathname ... expression
DESCRIPTION
The find command recursively searches the directory tree for
each specified pathname, seeking files that match a Boolean
expression written using the terms given later. The output
from find depends on the terms used in expression.
EXPRESSIONS
In the following descriptions, the argument number is a
decimal integer that can be specified as +number (more than
number), -number (less than number), or number (exactly
number).
-fstype type
TRUE if the file system to which the file belongs
is of the type type as follows:
nfs Network File System
pfs Parallel File System (PFS).
ufs UNIX file system (Berkeley fast file
system). This is the default.
-i number
TRUE if file has inode number.
-inum number
TRUE if file has inode number.
-name pattern
TRUE if pattern matches a filename. You can use
pattern-matching characters, provided they are
quoted.
-perm [-]octal_number
TRUE if the file permission code of the file
exactly matches octal_number (see the chmod com-
mand). If the optional - (dash) is present, this
expression evaluates to TRUE if the file permis-
sion code of the file meets or exceeds
octal_number.
The octal_number argument may be up to three octal
digits.
-perm [-]mode
The mode argument is identical to the chmod com-
mand syntax. This expression evaluates to TRUE if
the file has exactly these permissions. If the
optional - (dash) is present, this expression
evaluates to TRUE if the file meets or exceeds
these permissions.
-prune Always TRUE. Prunes the search tree at the file.
That is, if the current pathname is a directory,
find does not descend into that directory. In a
networking environment, this flag keeps the find
command from searching through remote file sys-
tems.
-type type
TRUE if the file type is of the specified type as
follows:
b Block special file
c Character special file
d Directory
f Plain file
l Symbolic link
p FIFO (a named pipe)
s Socket
-links number
TRUE if the file has number links. The argument
number is a decimal integer that can be specified
as +number (more than number), -number (less than
number), or number (exactly number). See the ln
command.
-user user
TRUE if the file belongs to user. If user is
numeric and does not appear as a login name in the
/etc/passwd file, it is interpreted as a user ID.
-nouser TRUE if the file belongs to a user ID for which
the getpwuid() function returns null.
-group group
TRUE if the file belongs to group. If group is
numeric and does not appear as a group name in the
/etc/group file, it is interpreted as a group ID.
-nogroup TRUE if the file belongs to a group ID for which
the getgrgid() function returns null.
-size number[c | k]
TRUE if the file is number blocks long (512 bytes
per block). For this comparison, the file size is
rounded up to the nearest block. If the c argument
is present, the expression evaluates to TRUE if
the file is number bytes long. If the k argument
is present, the expression evaluates to TRUE if
the file is number kilobytes long. For this com-
parison, the file size is rounded up to the
nearest kilobyte.
The argument number is a decimal integer that can
be specified as +number (more than number),
-number (less than number), or number (exactly
number).
-atime number
TRUE if the file was accessed in the past number
days. The argument number is a decimal integer
that can be specified as +number (more than
number), -number (less than number), or number
(exactly number).
-mtime number
TRUE if the file was modified in the past number
days. The argument number is a decimal integer
that can be specified as +number (more than
number), -number (less than number), or number
(exactly number).
-ctime number
TRUE if the file inode was changed in the past
number days. The argument number is a decimal
integer that can be specified as +number (more
than number), -number (less than number), or
number (exactly number).
-exec command
TRUE if the command runs and returns a 0 (zero)
value as exit status. The end of command must be
punctuated by a quoted or escaped ; (semicolon).
The command parameter { } is replaced by the
current pathname. If shell quoting is used in com-
mand, each word in the command must be quoted
separately. Also, the characters ; (semicolon) and
{ } (braces) must appear as separate words on a
command line.
-ok command
This expression is equivalent to -exec, except
that the find command first asks you whether it
should start command. If your response begins with
y, or the locale's equivalent of a y, command is
started. The end of command must be punctuated by
a quoted or escaped semicolon. If shell quoting is
used in command, each word in the command must be
quoted separately. Also, the characters ; (semi-
colon) and { } (braces) must appear as separate
words on a command line.
-print Always TRUE; causes the current pathname to be
displayed. The find command assumes a -print
expression, unless the -exec, ls, or -ok expres-
sions are present.
-cpio device
Writes the current file to device in cpio format.
See the cpio command.
-ncpio size
Sets the input/output size (5120 bytes by default)
to size.
-newer file
TRUE if the current file was modified more
recently than the file indicated by file.
-depth Always TRUE. This causes the descent of the direc-
tory hierarchy to be done so that all entries in a
directory are affected before the directory
itself. This can be useful when find is used with
cpio to transfer files that are contained in
directories without write permission.
e( expression e)
TRUE if expression is TRUE.
-ls Always TRUE; causes pathname to be printed
together with its associated statistics. These
include, respectively, inode number, size in kilo-
bytes (1024 bytes), protection mode, number of
hard links, user, group, size in bytes, and modif-
ication time. If the file is a special file, the
size field will instead contain the major and
minor device numbers. If the file is a symbolic
link, the pathname of the linked-to file is
printed preceded by ->. The format is identical to
that of ls -gilds (note that formatting is done
internally, without executing ls.)
-xdev Always TRUE; causes find to not traverse down into
a file system different from the one on which
current pathname resides.
The primaries may be combined using the following operators
(in descending order of precedence):
1. A parenthesized group of primaries and operators
(parentheses are special to the shell and must be
escaped).
2. The negation of a primary (! is the unary not operator).
3. Concatenation of primaries (the and operation is implied
by the juxtaposition of two primaries or may be expli-
citly stated as -a).
4. Alternation of primaries (-o is the or operator).
To avoid unpredictable results when using a range expression
to match a class of characters, use a character class
expression rather than a standard range expression. For
information about character class expressions, see the grep
command.
EXAMPLES
1. To list all files in the file system with a given base
filename, enter:
find / -name .profile
This searches the entire file system and writes the com-
plete pathnames of all files named .profile. The /
(backslash) tells find to search the root directory and
all of its subdirectories. This may take a while, so it
is best to limit the search by specifying the direc-
tories where you think the files might be.
2. To list the files with a specific permission code in the
current directory tree, enter:
find . -perm 0600
This lists the names of the files that have only
owner-read and owner-write permission. The . (dot) tells
find to search the current directory and its subdirec-
tories. See the chmod command for details about permis-
sion codes. Alternatively, you could enter the follow-
ing:
find . -perm u+rw
3. To search several directories for files with certain
permission codes, enter:
find manual clients proposals -perm -0600
This lists the names of the files that have owner-read
and owner-write permission and possibly other permis-
sions. The directories manual, clients, and proposals,
and their subdirectories, are searched. Note that -perm
0600 in the previous example selects only files with
permission codes that match 0600 exactly. In this exam-
ple, -perm -0600 selects files with permission codes
that allow at least the accesses indicated by 0600. This
also matches the permission codes 0622 and 2744.
4. To search for regular files with multiple links, enter:
find . -type f -links +1
This lists the names of the ordinary files (-type f)
that have more than one link (-links +1). Note that
every directory has at least two links: the entry in its
parent directory and its own . (dot) entry. See the ln
command for details about multiple file links.
5. To remove all files named a.out or *.o that have not
been accessed for a week and that are not mounted using
nfs, enter:
find / e( -name a.out -o -name (aa*.o(aa e) -atime +7 \
-exec \rm {} e; -o -fstype nfs -prune
6. To use the find command on PFS:
find /pfs -fstype pfs -print
/pfs
/pfs/f1
/pfs/f2
/pfs/f3
/pfs/d1
/pfs/d1/f1
/pfs/d1/f2
/pfs/d1/f3
/pfs/d1/f4
FILES
/etc/group
Contains group information.
/etc/passwd
Contains user information.
RETURN VALUES
The find command returns a 0 (zero) if all of the paths were
visited without error. find returns a nonzero value if it
encountered an error.
SEE ALSO
Commands: chmod(1), cpio(1), grep(1)/ egrep(1)/ fgrep(1),
ln(1), sh(1), test(1).
Functions: stat(2).
Files: fs(4).
Acknowledgement and Disclaimer