find(1) find(1)
NAME
find - find files
SYNOPSIS
find pathname_list [expression]
DESCRIPTION
The find command recursively descends the directory hierarchy for each
path name in pathname_list (that is, one or more path names) seeking
files that match a Boolean expression written in the primaries given
below. By default, find does not follow symbolic links.
The Boolean expression is evaluated using short-circuit evaluation.
This means that whenever the result of a Boolean operation (AND or OR)
is known from evaluating the left-hand argument, the right-hand
argument is not evaluated.
In the descriptions of the primaries, the argument n represents a
decimal integer; +n means more than n, -n means less than n, and n
means exactly n.
The following primaries are recognized:
-depth A position-independent term which 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. It is
also useful when using cpio(1) and the
modification dates of directories must be
preserved. Always true.
-follow A position-independent term which causes find
to follow symbolic links. Always true.
-fsonly FStype A position-independent term which causes find
to stop descending any directory whose file
system is not of the type specified by
FStype, where FStype is one of cdfs, hfs, or
nfs, representing the CDFS, HFS, or NFS file
system type, respectively.
In this context, mount points inherit the
FStype of their parent directory. This means
that when -fsonly hfs has been specified and
find encounters an NFS mount point that is
mounted on an HFS file system, the mount
point will be visited but entries below that
mount point will not. It is important to
Hewlett-Packard Company - 1 - HP-UX Release 10.20: July 1996
find(1) find(1)
note that when -fsonly nfs has been
specified, any HFS file systems that are
beneath the mount point of an NFS file system
are not traversed. Always true.
-xdev A position-independent term that causes find
to avoid crossing any file system mount
points that exist below starting points
enumerated in pathname_list. The mount point
itself is visited, but entries below the
mount point are not. Always true.
-mountstop Identical to -xdev. This primary is provided
for backward compatibility only. -xdev is
preferred over -mountstop.
-name file True if file matches the last component of
the current file name. The matching is
performed according to Pattern Matching
Notation (see regexp(5)).
-path file Same as -name except the full path (as would
be output by -print) is used instead of just
the base name. Note that / characters are
not treated as a special case. For example,
*/.profile matches ./home/fred/.profile.
-perm [-]mode In this primary, the argument mode is used to
represent file mode bits. The argument is
identical in format to the mode operand as
described in chmod(1), with the exception
that the first character must not be the -
operator. When using the symbolic form of
mode, the starting template is assumed to
have all file mode bits cleared.
If the leading minus is omitted, this primary
is true when the file permission bits exactly
match the value of mode. Bits associated
with the symbolic attributes s (set-user-ID,
set-group-ID) and t (sticky bit) are ignored
when the minus is omitted.
If mode is preceded by a minus, this primary
is true if all of the bits that are set in
mode are also set in the file permission
bits. In this case, the bits associated with
the symbolic attributes s and t are
significant.
Hewlett-Packard Company - 2 - HP-UX Release 10.20: July 1996
find(1) find(1)
-fstype FStype True if the file system to which the file
belongs is of type FStype, where FStype is
one of cdfs, hfs, or nfs, corresponding to
the CDFS, HFS, or NFS file system type,
respectively.
-type c True if the type of the file is c, where c is
one of:
f Regular file
d Directory
b Block special file
c Character special file
p FIFO (named pipe)
l Symbolic link
s Socket
n Network special file
M Mount point
-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. The uname operand can be
preceded by a + or - to modify the comparison
operation as described previously.
-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. The gname operand can be preceded by a +
or - to modify the comparison operation as
described previously.
-nouser True if the file belongs to a user ID that is
not listed in the password database. See
passwd(4).
-nogroup True if the file belongs to a group ID that
is not listed in the group database. See
group(4).
-size n[c] True if the file is n blocks long. If n is
followed by a c, the size is in bytes.
-atime n True if the file has been accessed in n days.
The access time of directories in
pathname_list is changed by find itself.
-mtime n True if the file has been modified in n days.
Hewlett-Packard Company - 3 - HP-UX Release 10.20: July 1996
find(1) find(1)
-ctime n True if the file inode has been changed in n
days.
-newer file True if the current file has been modified
more recently than the argument file.
-newer[tv1[tv2]] file True if the indicated time value (tv1) of the
current file is newer than the indicated time
value (tv2) of file. The time values tv1 and
tv2 are each selected from the set of
characters:
a The time the file was last accessed
c The time the inode of the file was
last modified
m The time the file was last modified
If the tv2 character is omitted, it defaults
to m. Note that the -newer option is
equivalent to -newermm.
Syntax examples;
-newera file
-newermc file
-inum n True if the file serial number (inode number)
is n. Note that file serial numbers are
unique only within a given file system.
Therefore, matching file serial numbers does
not guarantee that the referenced files are
the same unless you restrict the search to a
single file system.
-linkedto path True if the file is the same physical file as
the file specified by path (i.e., linked to
path). This primary is similar to -inum, but
correctly detects when a file is hard-linked
to path, even when multiple file systems are
searched.
-print Causes the current path name to be printed.
Always true.
-exec cmd True if the executed cmd returns a zero value
as exit status. The end of cmd must be
punctuated by a semicolon (semicolon is
special to the shell and must be escaped).
Any command argument {} is replaced by the
current path name.
Hewlett-Packard Company - 4 - HP-UX Release 10.20: July 1996
find(1) find(1)
-ok cmd Same as -exec except that the generated
command line is printed with a question mark
first, and is executed only if the user
responds by typing y.
-cpio device Write the current file on device in cpio(4)
format (5120-byte records). The use of -cpio
implies -depth. Always true.
-ncpio Same as -cpio but adds the -c option to cpio.
The use of -ncpio implies -depth. Always
true.
-prune If the current entry is a directory, cause
find to skip that directory. This can be
useful to avoid walking certain directories,
or to avoid recursive loops when using cpio
-p. Note, however, that -prune is useless if
the -depth option has also been given. See
the description of -only and the EXAMPLES
section, below, for more information. Always
true.
-only This is a positive-logic version of -prune.
A -prune is performed after every directory,
unless -only is successfully evaluated for
that directory. As an example, the following
three commands are equivalent:
find . -fsonly hfs -print
find . -print -fstype hfs -only
find . -print ! -fstype hfs -prune
Note, however, that -only is useless if the
-depth option has also been given. Always
true.
( expression ) True if the parenthesized expression is true.
The spaces are required. Parentheses are
special to the shell and must be escaped, as
in \( and \).
Primaries can be combined by using the following operators (in order
of decreasing precedence):
! expression Logical NOT operator. True if
expression is not true.
expression [-a] expression Logical AND operator. True if both of
the expressions are true.
Hewlett-Packard Company - 5 - HP-UX Release 10.20: July 1996
find(1) find(1)
expression -o expression Logical OR operator. True if either or
both of the expressions are true.
If expression is omitted, or if none of -print, -ok, -exec, -cpio, or
-ncpio is specified, -print is assumed.
Access Control Lists
The -acl primary enables the user to search for access control list
entries. It is true if the file's access control list matches an
access control list pattern or contains optional access control list
entries (see acl(5)). It has three forms:
-acl aclpatt Match all files whose access control list
includes all (zero or more) pattern entries
specified by the aclpatt pattern.
-acl =aclpatt Match a file only if its access control list
includes all (zero or more) pattern entries
specified by the aclpatt pattern, and every
entry in its access control list is matched
by at least one pattern entry specified in
the aclpatt pattern.
-acl opt Match all files containing optional access
control list entries.
The aclpatt string can be given as an operator or short form pattern;
see acl(5).
By default, -acl is true for files whose access control lists include
all the (zero or more) access control list patterns in aclpatt. A
file's access control list can also contain unmatched entries.
If aclpatt begins with =, the remainder of the string must match all
entries in a file's access control list.
The aclpatt string (by default, or the part following =) can be either
an access control list or an access control list pattern. However, if
it is an access control list, aclpatt must include at least the three
base entries ((user.%, mode), (%.group, mode), and (%.%, mode)).
As a special case, if aclpatt is the word opt, the primary is true for
files with access control list entries.
EXTERNAL INFLUENCES
Environment Variables
If an internationalization variable is not specified or is null, it
defaults to the value of LANG.
If LANG is not specified or is null, it defaults to C (see lang(5)).
Hewlett-Packard Company - 6 - HP-UX Release 10.20: July 1996
find(1) find(1)
If LC_ALL is set to a nonempty string value, it overrides the values
of all the other internationalization variables.
If any internationalization variable contains an invalid setting, all
internationalization variables default to C (see environ(5)).
LC_CTYPE determines the interpretation of text as single and/or
multibyte characters, the classification of characters as printable,
and the characters matched by character class expressions in regular
expressions.
LC_MESSAGES determines the locale that should be used to affect the
format and contents of diagnostic messages written to standard error
and informative messages written to standard output.
NLSPATH determines the location of message catalogues for the
processing of LC_MESSAGES.
International Code Set Support
Single- and multibyte character code sets are supported.
EXAMPLES
Search the two directories /example and /new/example for files
containing the string Where are you and print the names of the files:
find /example /new/example -exec grep -l 'Where are you' {} \;
Remove all files named a.out or *.o that have not been accessed for a
week:
find / \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \;
Note that the spaces delimiting the escaped parentheses are
required.
Print the names of all files on this machine. Avoid walking nfs
directories while still printing the nfs mount points:
find / -fsonly hfs -print
Copy the entire file system to a disk mounted on /Disk, avoiding the
recursive copy problem. Both commands are equivalent (note the use of
-path instead of -name):
cd /; find . ! -path ./Disk -only -print | cpio -pdxm /Disk
cd /; find . -path ./Disk -prune -o -print | cpio -pdxm /Disk
Copy the root disk to a disk mounted on /Disk, skipping all mounted
file systems below /. Note that -xdev does not cause / to be skipped,
even though it is a mount point. This is because / is the starting
Hewlett-Packard Company - 7 - HP-UX Release 10.20: July 1996
find(1) find(1)
point and -xdev only affects entries below starting points.
cd /; find . -xdev -print | cpio -pdm /Disk
Change permissions on all regular files in a directory subtree to mode
444, and permissions on all directories to 555:
find <pathname> -type f -print | xargs chmod 444
find <pathname> -type d -print | xargs chmod 555
Note that output from find was piped to xargs(1) instead of using
the -exec primary. This is because when a large number of files
or directories is to be processed by a single command, the -exec
primary spawns a separate process for each file or directory,
whereas xargs collects file names or directory names into
multiple arguments to a single chmod command, resulting in fewer
processes and greater system efficiency.
Access Control List Examples
Find all files not owned by user karl that have access control lists
with at least one entry associated with karl, and one entry for no
specific user in group bin with the read bit on and the write bit off:
find / ! -user karl -acl 'karl.*, %.bin+r-w' -print
Find all files that have a read bit set in any access control list
entry:
find / -acl '*.*+r' -print
Find all files that have the write bit unset and execute bit set in
every access control list entry:
find / -acl '=*.*-w+x' -print
Find all files that have optional access control list entries:
find / -acl opt -print
DEPENDENCIES
NFS
The -acl primary is always false for NFS files.
WARNINGS
Because of interoperability goals, cpio does not support archiving
files larger than 2GB or files that have user/group IDs larger than
60,000 (60K). Files with user/group IDs greater than 60K are archived
and restored under the user/group ID of the current process.
AUTHOR
find was developed by AT&T and HP.
Hewlett-Packard Company - 8 - HP-UX Release 10.20: July 1996
find(1) find(1)
FILES
/etc/group Group names
/etc/mnttab Mount points
/etc/passwd User names
SEE ALSO
chacl(1), chmod(1), cpio(1), sh(1), test(1), xargs(1), mknod(2),
stat(2), cpio(4), fs(4), group(4), passwd(4), acl(5), environ(5),
lang(5), regexp(5).
STANDARDS CONFORMANCE
find: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
Hewlett-Packard Company - 9 - HP-UX Release 10.20: July 1996