Previous Table of Contents Next


Module 55
find

DESCRIPTION

The external find command locates files that match specified expressions. It starts searching for files in the given directory and continues its search through all subdirectories. Multiple directories may be searched by providing the name of each directory you wish searched. The expressions used by find may be based on the filename, file attributes, or a combination of the two.

COMMAND FORMAT

Following is the general format of the find command.

     find pathname_list expression_list

BSD (Berkeley)
find pathname_list expression_list
find name

Options

The following describes the expression_list and their arguments you may use with the find command. The expression_list consists of one or more of the following Boolean expressions. A Boolean expression is either true or false. It the expression matches a filename or a file attribute then the expression is true; otherwise, the expression is false.

In the following descriptions the value n refers to an exact number. The +n notation refers to more than n, and -n refers to less than n. An n may be replaced with a tu or -n.

Expression_list

-atime n True if the file was accessed n days ago. find updates the access times of the directories in the pathname_list.
-ctime n True if the file's status was changed n days ago. A change to a file means the inode of the file was modified.
-depth Always true if specified on the command line. Causes find to descend the directory structures and perform the specified options on the subdirectories and files before processing the top directory. You may find this useful when using find to pipe pathnames to cpio. If you do not have write permission in directories this will allow you to transfer the files to the archive file.
-exec cmd True if the command cmd executes successfully and returns a zero exit status. You can use a set of braces ({}) to signify the presence of the current pathname. The cmd command must end with an escaped semicolon (\;). For example,
                     find . -name '*.o' -exec rm {} \;
would remove all files ending with a .o from the current directory structure.
-fstype type True if the file system in which the file resides is of the given type. Valid types are usually nfs or 4.2, where nfs refers to Network File System file systems and 4.2 refers to local BSD4.2 type file systems.
-group name True if the file belongs to the group name. You may specify a group ID instead of a group name.
-inum n True if the file has inode number n.
-links n True if the file has n links.
-local True if the specified file physically resides on the local UNIX system. This is useful when searching directories on systems that are networked together and share disk space.
-mount True if specified on the command line. Confines the search to the file system containing the specified directory. This is useful when you only want to search one file system. If no directory is specified, the search is performed on the current directory.
-mtime n True if the file's contents were modified n days ago.
-name file True if the filename matches file. The shell's filename generation characters may be used if enclosed in quotes. For example,
                     find . -name '*.c' -print
prints all files ending with a .c in the current directory or any of its subdirectories.
-newer file True if the current file is newer than the specified file. The modification dates are compared to decide which is newer.
-nogroup True if the file belongs to a group (groupid) not in /etc/passwd.
-nouser True if the file belongs to a user (userid) not in /etc/passwd.
-ok cmd Same as the -exec option except the command is displayed followed by a question mark. The command cmd is executed only if you respond with a y.
-perm on True if the permissions of the file matches the octal number on. Refer to Module 17 on chmod for a full description of the octal number representation used for on. You can prefix on with a minus sign to force the comparison of only the bits that are set in on to the file permission.
-print Always true if specified on the command line. Causes the current pathname to be displayed.
-prune Always true. Prunes the search path at the current directory level. If the current pathname is a directory, find will not descend into the directory.
-size n[c] True if the file contains n blocks. If the n is followed by c then n is counted in characters instead of blocks.
-type c True if the file type is type c, where c is one of the following.
Type Description
b A block special device file
c A character special device file
d A directory
f A plain file (SV only)
p A named pipe (FIFO) (SV only)
f A plain file
l A symbolic link to a file
s A socket (BSD only)
-user name True if the file belongs to the user name. You may specify a user ID instead of a user's login name.


Previous Table of Contents Next