HP NonStop G-Series User Manual

Page 150

Advertising
background image

/usr/chang/reports96
/usr/chang/reports96/reportjan
/usr/chang/reports96/reportjan.tmp
/usr/chang/reports96/reportmay
/usr/chang/reports96/reportmay.tmp
/usr/chang/reports96/reportsept
/usr/chang/reports96/reportdec
/usr/chang/reports97
/usr/chang/reports97/reportjan
/usr/chang/reports97/reportmay
/usr/chang/reports97/reportsept
/usr/chang/reports97/reportsept.tmp
/usr/chang/reports97/reportdec
/usr/chang/reports98
/usr/chang/reports98/reportjan
/usr/chang/reports98/reportmay
/usr/chang/reports98/reportmay.tmp
/usr/chang/reports98/reportsept

You can also use the find command to search for files and then execute a command on the
selected files. The general format for this search is the following:

find pathname -name filename -print -exec command {} \;

The pathname entry specifies the directories you wish to search. The -name entry specifies that
you wish to specify a filename. The filename entry can specify a single file or it can specify
a number of files by using pattern-matching characters. If you want to search for a number of files
with pattern-matching characters, you must enclose the filename in “ ” (double quotes). The
-print

entry specifies that you wish to display the pathnames of the files acted on by the command.

The -exec entry specifies that you wish to execute a command upon the selected files. The command
entry specifies the command you wish to execute upon the selected files. The {} (braces) indicate
that the output of the find command should be a command line argument for command. The \;
(backslash and semicolon) are an escape sequence: the semicolon specifies the end of the command,
and the backslash prevents the shell from interpreting the semicolon.

For example, suppose that you are user chang and want to delete all the temporary files shown
in the preceding example. Those files begin with the word report and end with .tmp. Enter the
following:

$ find /usr/chang -name "report*.tmp" -print -exec rm {} \;

/usr/chang/reports96/reportjan.tmp
/usr/chang/reports96/reportmay.tmp
/usr/chang/reports97/reportsept.tmp
/usr/chang/reports98/reportmay.tmp

If you are searching the root directory, the /G (Guardian files) and /E (remote nodes) directories
are included in the search, which could result in a more extensive and time-consuming search than
you intended. You can exclude the /G and /E directories from the search by specifying the -W
NOG

and -W NOE flags, respectively, on the find command. For example, the following command

searches for the file named f1 only on the local node; Guardian files and files on remote nodes
are excluded:

find / -W NOG -W NOE -name f1 -print

There are many more functions that the find command provides. For more information, see the
find(1)

command reference page either online or in the Open System Services Shell and Utilities

Reference Manual.

150

Productivity Tools: grep and find

Advertising
This manual is related to the following products: