Commands revisited: pipes and redirection

Putting the output of a command into a file

You have already seen one example of how to put the output of a command into a file: cat > file

Here, cat opens a file and waits for you to type into it. The file is closed when you press <Ctrl>D, the end-of-file (EOF) character. The greater-than sign is the redirection symbol; it tells the computer you want the output of cat to go into a file instead of the usual place. This is called ``redirecting standard output,'' or simply ``redirection.''

You can use redirection with any command that prints information on the screen. For example, you could redirect the output of ls into a file and then print this file to get a printed directory listing.

Try printing a long listing of the files in your home directory:

  1. If you are not already in your home directory, go there by typing cd and pressing <Enter>.

  2. List the files into a file called filelist: type l > filelist and press <Enter>.

  3. Send the file filelist to the printer by typing lp filelist and pressing <Enter>.
The usual place the output of a command goes is known as standard output. Standard output is usually your screen.

The usual place a command gets its input from is known as standard input. Standard input is usually your keyboard. You will learn how to use a file as standard input later in this chapter.

Standard output and standard input are sometimes referred to as ``standard out'' and ``standard in,'' or ``stdout'' and ``stdin.''

Next topic: Using a file as input to a command
Previous topic: Commands revisited: pipes and redirection

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003