FIND(1,C) AIX Commands Reference FIND(1,C)
-------------------------------------------------------------------------------
find
PURPOSE
Finds files matching expression.
SYNTAX
find --- path --- expression ---|
^ |
+--------+
find --- pattern ---|
Note: The find command should be used in conjunction with the "- print"
option.
DESCRIPTION
The find command recursively searches the directory tree for each specified
path, seeking files that match a Boolean expression written using the terms
given below. The output from the find command depends on the terms used in
expression.
When searching a directory tree, symbolic links are treated as terminal nodes
even when they point to directories. The exception is when path is a symbolic
link that points to a directory, in which case that directory tree will be
searched.
The second form rapidly searches a data base for all pathnames which match
pattern. Usually the data base is recomputed weekly by the updatedb script
which is run from the /usr/adm/weekly shell script. The data base contains the
pathnames of all files which are publicly accessible. If escaped, normal shell
"globbing" characters (* , ?, [, ] may be used in pattern, but the matching
differs in that no characters (for example, /) have to be matched explicitly.
As a special case, a simple pattern containing no globbing characters is
matched as though it were *pattern*; if any globbing character appears, there
are no implicit globbing characters.
EXPRESSION TERMS
In the following descriptions, the parameter num is a decimal integer that can
be specified as +num (more than num), -num (less than num), or num (exactly
num).
Processed November 8, 1990 FIND(1,C) 1
FIND(1,C) AIX Commands Reference FIND(1,C)
-fstype type True if the file system to which the file belongs is of the
type type, where type is typically nfs or aix.
-inum n True, if file has inode n.
-name file True, if file matches the file name. You can use
pattern-matching characters, provided they are quoted. In an
expression such as [a-z], the minus means "through" according
to the current collating sequence. A collating sequence may
define equivalence classes for use in character ranges. See
"Introduction to International Character Support" in Managing
the AIX Operating System for more information on collating
sequences and equivalence classes.
-perm onum True, if the file permission code of the file exactly matches
the octal number onum (see "chmod" for an explanation of file
permissions). The onum parameter may be up to three octal
digits. If you want to test the higher-order permission bits
(the set-user-ID bit or set-group-ID bit, for example),
prefix the onum parameter with a minus (-) sign. This makes
more flag bits significant (see the stat system call for an
explanation of the additional bits), and also changes the
comparison to:
(flags"&"onum)==onum
-prune Always yields true. Has the side effect of pruning the
search tree at the file. That is, if the current path name
is a directory, find will not descend into that directory.
-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
h Hidden directory
l Symbolic link
p FIFO (a named pipe).
s Socket
-links num True, if the file has num links. See "ln."
-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 interpreted as a user ID.
-nouser True, if the file belongs to a user not in the /etc/passwd
data base.
Processed November 8, 1990 FIND(1,C) 2
FIND(1,C) AIX Commands Reference FIND(1,C)
-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
interpreted as a group ID.
-nogroup True, if the file belongs to a group not in the /etc/group
data base.
-size num True, if the file is num blocks long (512 bytes per block).
For this comparison the file size is rounded up to the
nearest block.
-atime num True, if the file has been accessed in num days.
-mtime num True, if the file has been modified in num days.
-ctime num True, if the file inode has been changed in num days.
-exec cmd True, if cmd runs and returns a zero value as exit status.
The end of cmd must be punctuated by a quoted or escaped
semicolon. A command parameter "{}" is replaced by the
current path name.
-ok cmd The find command asks you whether it should start cmd. If
your response begins with "y", cmd is started. The end of
cmd must be punctuated by a quoted or escaped semicolon.
-print Always true; causes the current path name to be displayed.
The find command does not display path names unless you
specify this expression term.
-hidden Always true; causes hidden directories encountered in the
descent to be treated as directories and their contents
searched. Otherwise, hidden directories are treated as
ordinary files and are not searched.
-cpio device Write the current file to device in cpio format. See "cpio."
-newer file True if the current file has been modified more recently than
the file indicated by file.
-depth Always true. This causes the descent of the directory
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.
-ls Always true; causes current pathname to be printed together
with its associated statistics. These include (respectively)
inode number, size in kilobytes (1024 bytes), protection
mode, number of hard links, user, group, size in bytes, and
modification time. If the file is a special file, the size
field will instead contain the major and minor device
Processed November 8, 1990 FIND(1,C) 3
FIND(1,C) AIX Commands Reference FIND(1,C)
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 -gildsN" (note however that
formatting is done internally, without executing the ls.)
-xdev Always true; causes find not to traverse down into a file
system different from the one on which current argument
pathname resides.
\( expression \) True, if the expression in parentheses is true.
You may perform the following logical operations on these terms (listed in
order of decreasing precedence):
o Negate a term (! is the NOT operator).
o Concatenate terms (juxtaposing two terms implies the AND operation).
o Alternate terms (-o is the OR operator).
EXAMPLES
1. To list all files in the file system with a given base file name:
find / -name .profile -print
This command searches the entire file system and writes the complete path
names of all files named ".profile". The "/" tells the find command 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 directories
where you think the files might be.
2. To list the files with a specific permission code in the current directory
tree:
find . -perm 0600 -print
This command 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 subdirectories. See the command: "chmod" for details
about permission codes.
3. To search several directories for files with certain permission codes:
find manual clients proposals -perm -0600 -print
This command lists the names of the files that have owner-read and
owner-write permission and possibly other permissions. 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 example,
"-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".
Processed November 8, 1990 FIND(1,C) 4
FIND(1,C) AIX Commands Reference FIND(1,C)
4. To search for regular files with multiple links:
find . -type f -links +1 -print
This command lists the names of the ordinary files ("-type f") that have
more than one link ("-links +1"). Every directory has at least two links:
the entry in its parent directory and its own "." (dot) entry. See "ln"
for details about multiple file links.
5. To back up selected files in cpio format:
find . -name "*.c" -cpio /dev/rfd0
This command saves all the ".c" files onto the diskette in cpio command
format. See "cpio" for details. The pattern "*.c" must be quoted to
prevent the shell from treating the * as a pattern-matching character.
This is a special case in which the find command itself decodes the
pattern-matching characters.
6. To perform an action on all files that meet complex requirements:
find . \( -name a.out -o -name "*.o" \) -atime +7 -exec rm {} \;
This command deletes ("-exec rm {} \;") all files named "a.out" or that end
with ".o", and that were last accessed over seven days ago ("-atime +7").
The "-o" flag is the logical OR operator.
FILES
/etc/group File that contains all known groups.
/etc/passwd File that contains all known users.
RELATED INFORMATION
See the following commands: "cpio," "sh, Rsh," and "test."
See the stat system call and the cpio command and fs files in AIX Operating
System Technical Reference.
See the "Introduction to International Character Support" in Managing the AIX
Operating System.
Processed November 8, 1990 FIND(1,C) 5