| The find
command is one of the most powerful and useful commands available to a
UNIX environment user. This command can be used to find files based on
specific criteria. Once a file or group of files that match a search
criterion is found, another command can be executed on the matching
files. The find
command can be used for many purposes including deleting, backing up,
or printing files. The find
command can be used to locate files on your local hard drive or on
remote servers. Try to avoid using the find
command on remote server file systems since it may place a heavy load
on the CPU and hard disk of the server, which will decrease
performance for other users. When searching for files with the find
command, try to start at the lowest point in the directory structure where
you will most likely find them. The find
command starts at the point in the directory hierarchy specified and
searches all directories and subdirectories below that point. A search
of your hard drive starting at the root can take a long time. Once a
file is found, it is listed with the starting directory and any
subdirectories below it.
Path Options
The Path in the syntax shown in Figure
names the directory
where the search begins.
Path can be a tilde (~) representing your home directory, a dot (.)
representing the current directory, an absolute or relative pathname,
or even the root directory.
Search Expression Options
The Expression is one or more search criteria options that indicate
what to look for and is specified by one or more values. Basic find
options include file name, type, and size. If more than one expression
is specified, find
treats the statement as an "and" request
and all listed expressions must be verified as true or present. The -o
(or) option can be used between expressions to allow for an
"or" type of criteria definition which means that if any of
the expressions is true, the file will be found. Many search
expressions will require a value to match and in some cases
metacharacters, or wildcards, may be used for the arguments. Examples
of search expressions are shown in Figure . The expressions
used with the find
command evaluate as true or false.
Action Options
The Action at the end of the command is optional and can be used to
execute various commands after the desired file(s) have been found.
Figure shows examples of actions that can be performed.
Note: Releases of the Solaris
environment previous to 2.5 required the -print action in order to
see the output from the find command on the screen.
Using the find
Command
Figure shows several examples using the
find
command. A brief explanation of each of these follows:
- Specifies an absolute pathname to
start in and finds files and directories with a particular name.
- Specifies an absolute pathname to
start in and finds file names with a character string in a
specific location using a metacharacter or wildcard. The quotes
are necessary or the find
command will look for an asterisk in the
first position.
- Specifies the home directory (tilde
~) as a starting point. Finds a particular file by name and
performs the action of deleting it.
Note: core files are memory
dumps that are created when a program abnormally ends.
- Specifies a relative pathname as a starting point. Finds files that have a file type of
directory (d).
- Specifies the current directory (dot .) as a starting point.
Finds files that have a modification date (mtime) of older than X
numbers of days.
- Specifies an absolute pathname to
start in and Finds file that are greater than a specified size.
- Specifies the home directory (tilde
~) as a starting point. Finds files with a specific permission
level (777 is open permissions and covered later in the course). Redirects the output to a file
for later viewing.
- Specifies the current directory (dot
.) as a starting point. Finds files that are owned by a particular
user and lists them. Redirects listing output to a file for later
viewing.
 |
 |
Interactive
Media Activity
(Flash,
100 kB) |
| |
Finding
Files
In this media activity, you are logged in as user2 and your current working directory is: /home/user2. Refer to the Class File Tree Structure by clicking the 'tree' button located on the Menu Bar and type the commands that would accomplish the requested objectives.
Note: Be sure to press enter after each one. Click on step 1 to begin.
|
|
|
|
|