Go to the previous, next section.

Redirecting output

To send the output generated by a UNIX command to a file rather than to the terminal, enter the command as follows:

command options argument > outputfile

Replace command, options, and argument with the full command as you would normally enter it. Replace outputfile with the file to which the command is to send its output.

For example, consider the grep command, which is used to search a file for a string and write all the lines that contain that string to the standard output device. In the following example, the grep command searches the file `myprog.c' for the string `counter' and prints all the lines that contain counter at the terminal:

grep counter myprog.c

The grep command could also be used to place all the lines that contain `counter' in a file called `counter-matches' instead. The following example shows how grep would do that if you redirected its output to `counter-matches':

grep counter myprog.c > counter-matches

You could then manipulate counter-matches as you would any other file.

Go to the previous, next section.