Previous Table of Contents Next

BSD (Berkeley)
The -mount option is not supported on most BSD systems. See the -xdev option that follows.
-ls Always true. The full pathname and all related statistics are displayed. The statistics are:
inode number
size in kilobytes (1024 bytes)
protection mode (-rwxr-x-r-- etc.)
number of hard links
size in bytes
modification time
This is the same listing as the ls -dgils command. If the file is a symbolic link, the pathname of the file being linked to is displayed. A "->" precedes the linked name.
-type Same as SV. BSD does not support the f or p type. It does support the s type for socket.
-xdev See -mount of System V options.


The following list describes the arguments that may be passed to the find command.

pathname_list This is a list of all directories to be searched by find. The names are separated by spaces or tabs. Each directory and all of its subdirectories are searched for matches. Pathnames may be relative pathnames. For example, to search the current directory you use the . (dot) notation.

BSD (Berkeley) Only
name List all files whose pathname contains name. Similar to the command:
                     find / -name '*name*' -print
but much faster because the database is searched instead of the actual file system. Shell name generation is supported.
The database is generated from a command in root's crontab. The default setup runs the command once a week.


You can combine the previously defined options using the following Boolean operators.

Operator Description

! The logical NOT operator. This operator negates the expression. For example,
                     find . ! -name '*.c' -print
prints all pathnames NOT ending with a .c.
-a The logical AND operator. You use this operator to combine options, causing the expression to be true only if both options or all options listed are true. It is implied in normal syntax. For example, the following two commands are equivalent.
                     find . -name '*.o' -size +5 -print
                      find . -name '*.o' -a -size +5 -print
These commands locate files ending with .o and containing 5 or more blocks of data.
-o The logical OR operator. You use the OR operator to cause the condition to be true if either option is true. For example,
                     find . -name '*.o' -o -name '*.c' -print
displays pathnames that end in .o or .c.
(expr) True if the expressions enclosed in the parentheses are true. The parentheses are special to the shell and must be escaped using backslashes, as in the command
                     find . \( -name '*.c' -o -name '*.o' \) -print


If you use the depth option at the root directory, find fails.


Refer to the chmod, cpio, ksh, and test commands described in modules 17, 25, 71, and 135.


The find command reads the /etc/passwd and /etc/group files to relate user IDs and group IDs to the symbolic names you use on the command line.


The return codes from find do not reflect whether or not files were located based on the options. Therefore, it is best to ignore the return codes.


The find command serves many purposes. Its claim to fame is the ability to descend the file system tree of UNIX. It provides a way to see the contents of an entire file system or any subdirectory structure.

It is the front end processor for the cpio command. It generates a list of pathnames that are passed into cpio, which then copies the contents of each pathname to the output archive file.

It also provides the ability to perform commands with the pathnames as arguments. You can search for certain filenames and remove them if they are older than a specified amount of time. The options are many and their abilities are powerful. Although it may be hard to understand at first, it is a command well worth learning.


In this activity you use the find command to locate all large files in the /usr directory, old files in the current directory, and filenames with special endings. Begin at the shell prompt in your HOME directory.

1.  Type find /usr -size +500 -print and press Return. The files in the /usr directory containing more than 500 blocks are displayed to your screen. The find command takes a while to run since it has to search the /usrfile system inode list. The output for each system will vary.
2.  Type find . -atime -2 -ok rm {} \; and press Return. This will prompt you with the name of each file that has been accessed in the last 2 days. If you answer with a "y" the file is removed.
     cj> find . -atime -2 -ok rm {} \;
     < rm ... ./myfile >?  _
3.  Type find . \( -name '*.[achoz]' -o -name '*.bak' \) -mtime -30 -print and press Return. This lists all files ending with an a, c, h, o, z, or bak and that have been modified within the last 30 days.
     cj> find . \( -name '*.[achoz]' -o -name '*.bak'\) -mtime -7 -print

Your output may differ depending on what files you have in your HOME directory.
4.  Turn to Module 86 to continue the learning sequence.

Previous Table of Contents Next