Using the find command in command substitution constructs
The find command is useful in command
substitution constructs. find displays the
names of files that have specified characteristics. For example:
find dir1 –name "*.c"
finds
all files in the directory dir1 whose names match the wildcard
pattern *.c. In other words, it finds all files in
that directory with names having the .c suffix.The command:
ls -l $(find dir1 –name "*.c")
finds
all the .c files and then uses ls to
display information about these files.Complicating things further, you could enter
ls -l $(find dir1 –name "*.c") | grep -F "Nov"
This
sets up a pipeline that displays ls information
only for files that were last changed in November. (To be perfectly
accurate, it also displays information about files that have the string Nov in
their names, too.)Another useful find option has the form:
find path –ctime number
This
says that you want to find files that have changed in the last number of
days. For example: ls -l $(find dir –ctime 1)
displays ls information
about all files that changed either yesterday or today.On many UNIX and AIX® systems, the find command
prints out the file names only if you specify the –print option.
Thus, you would have to enter:
find dir –name "*.c" –print
to
get the results just described. The z/OS UNIX find command
automatically prints its results without –print.
However, if you have an existing shell script or compatibility with UNIX systems is important to you,
you can use –print.For more information about the find command, see the find command description in z/OS UNIX System Services Command Reference.