find.1 (2010 09)
f
find(1) find(1)
find . -name ’*.o’ -exec ls -l {} \+
find . -name ’*.o’ -exec ls -l \+
Note that the curly braces, before plus sign, are optional.
• Print the names of all files on this machine. Avoid walking
nfs directories while still printing the
nfs mount points:
find / -fsonly hfs -print
• Match only local files, and do not 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
• 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 start-
ing 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. The + delimiter for the -exec primary can be used to
achieve the same efficiency.
Access Control List Examples
The following examples are for Access Control Lists.
• 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
HP-UX 11i Version 3: September 2010 − 7 − Hewlett-Packard Company 7