Linux shells provide this capability by connecting the output from one command to the input expected by another. In Linux terms, this is connecting the standard output from one command to the standard input of another. The pipe symbol automatically ties the two commands together and sends the output of the first to the second as input.
Linux actually provides two different ways of specifying that the output of one command is the input to another — by using a pipe to connect the two commands, or by what is known as redirecting IO, which stands for redirecting input/output.
The output of a file can also be redirected to a file, using the greater than sign (>), which simply creates a file containing the output of the command, as in the following example:
Is > listing.out
This command takes the output of the Is command and sends it to the file listing.out.
Linux supports combining commands and redirecting input and output by recognizing three different aspects of program input and output:
■ stdin: The standard input stream that is read from by a program
■ stdout: The standard output stream to which program output is sent
■ stderr: A specialized output stream known as standard error to which program error messages are written
You will encounter these terms as you become more familiar with executing shell commands because these are the cornerstones of creating complex commands by stringing together simple ones. Like the regular expressions discussed in the previous section, redirecting input and output is an extremely powerful feature of most Linux shells. Entire books have been written about shells such as bash and tcsh — search your favorite online bookseller for these if you want to become a true shell expert and amaze your friends with various complex shell tricks.
Was this article helpful?