Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chacl(1)

chmod(1)

cpio(1)

sh(1)

test(1)

xargs(1)

mknod(2)

stat(2)

cpio(4)

fs(4)

group(4)

passwd(4)

cdf(4)

acl(5)

environ(5)

lang(5)

regexp(5)

find(1)

NAME

find − find files

SYNOPSIS

find path-name-list [expression]

DESCRIPTION

find recursively descends the directory hierarchy for each path name in the path-name-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 is used as 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. 

-hidden A position-independent term which causes find to include hidden subdirectories (context-dependent files) in the directory hierarchy of each path name in the path-name-list. In addition, the normally hidden components of the path name become visible as when using the -print primary (see cdf(4)). Always true.

-fsonly type A position-independent term which causes find to stop descending any directory whose file system is not of the type specified by type, where type is one of nfs, cdfs, or hfs.  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 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 path-name-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 backwards compatibility only.  Use of -xdev is preferred over -mountstop. 

-name file True if file matches the last component of the current file name.  The matching is performed as specified by 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 basename.  Note that / characters are not treated as a special case.  For example, */.profile would match ./users/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 (setuid, setgid) 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. 

-fstype type True if the file system to which the file belongs is of type type, where type is one of hfs, cdfs, or nfs. 

-type c True if the type of the file is c, where c is:

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

H hidden directory (see cdf(4))

The use of -type H implies the -hidden primary (see above). 

-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. 

-devcid cname True if the file is a block or character special file whose st_rcnode value is equal to the cnode id of the cnode cname. If cname is numeric and does not appear as a cnode name in the /etc/clusterconf file, it is taken as a cnode ID .  See mknod(2)) for a description of cnode-specific device files. The cname 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).

-nodevcid True if the file is a block or character special file whose st_rcnode value is not listed in the /etc/clusterconf file.  See mknod(2).

-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 path-name-list is changed by find itself. 

-mtime n True if the file has been modified in n days. 

-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[acm[acm]] file
True if the indicated time value of the current file is newer than the indicated time of file. The time values are indicated from the set of characters a, c, and m, where:

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

The first [acm] specifies the time of the current file, the second [acm] specifies the time of file.  If only one [acm] is specified, the second time specifier defaults to m. 

-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. 

-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 (parentheses are special to the shell and must be escaped).

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.

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 are specified, -print is assumed. 

Access Control Lists

The following primary enables the user to search for access control list entries:

-acl aclpatt True if the file’s access control list matches an access control list pattern or contains optional access control list entries (see acl(5)). The -acl primary 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 of the -acl primary 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 ((u.%, mode), (%.g, 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

LC_COLLATE determines the collating sequence used in evaluating pattern matching notation for file name matching. 

LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, and the characters matched by character class expressions in pattern matching notation. 

LANG determines the language in which messages are displayed. 

If LC_COLLATE or LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable.  If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG.  If any internationalization variable contains an invalid setting, find behaves as if all internationalization variables are set to "C".  See environ(5).

International Code Set Support

Single- and multi-byte 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 in /bin that are context-dependent; that is, hidden directories:

find /bin -type H -print

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 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 are to be processed by a single command, the -exec primary spawns a separate process for each file or directory, whereas xargs collects filenames 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

WARNINGS

Access Control Lists

Access control list descriptions in this entry apply only to standard HP-UX operating systems.  If HP_UX BLS software has been installed, access control lists are handled differently.  Refer to HP-UX BLS documentation for information about access control lists in the HP-UX BLS environment. 

DEPENDENCIES

NFS The -acl primary is always false for NFS files. 

AUTHOR

find was developed by AT&T and HP. 

FILES

/etc/clusterconf cnode names

/etc/group group names

/etc/passwd user names

/etc/mnttab mount points

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), cdf(4), acl(5), environ(5), lang(5), regexp(5). 

STANDARDS CONFORMANCE

find: SVID2, XPG2, XPG3, proposed POSIX.2 FIPS (June 1990)

STANDARDS CONFORMANCE

find: SVID2, XPG2, XPG3, POSIX.2

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026