z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Using record-keeping commands

z/OS UNIX System Services User's Guide
SA23-2279-00

Record-keeping commands can be very helpful for programmers. For example, suppose you have a program that is split into several source files. For the sake of simplicity, assume that the source files all have the extension .c and are all stored in a subdirectory called src. (To read about extensions, see Naming files.)

It is often the case that you want to find out which source files in the subdirectory refer to a particular variable or function. You can do this very simply with the command:
grep 'name' src/*.c
The command checks all the appropriate files in the subdirectory src and displays the lines that contain the given name. Each line is labeled with the name of the file that contains the line. You can quickly find the use of a function or data object in source files.
As another example of using record-keeping commands, suppose that you are working on a large program and every few days you back up the source code for the program by copying it to a directory in a different file system (as a precaution). You would like to compare the current version of your source files with one of the saved versions, to find out what changes have been made between the two. The command:
diff oldfile newfile
prints out all the differences between two versions of a file, making comparisons possible.

The cksum command gives a checksum for each file. If applied to two versions of what was at one time the same file, cksum gives a convenient way to tell if the files are still the same. It does not, however, indicate what the differences are.

The find command also has applications to programming. For example, suppose you are looking for a particular C source program but cannot remember where it is stored.
find / –name '*.c'
searches all the files and file systems, starting at the root, and displays the names of all files with the .c extension.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014