Standard files and data pipes



Last revision August 3, 2004

Table of Contents:

  1. The Unix file system
  2. The directory tree
  3. File ownership and permissions
  4. Files as units
  5. Examining file contents
  6. Other commands
  7. Standard Files and Data Pipes

One of the most powerful features of the Unix shell is that it can manipulate the environment of processes so that a program's input or output files can be changed without modifying the program itself. Furthermore, the shell can arrange it so that output from one program can flow transparently to be input to another program. In this way, simple programs working together can accomplish complex tasks. This discussion of these input/output features applies specifically to the C-shell, although much of it is similar in the Bourne and other shells.

Definitions of standard files

Every process has a standard input, standard output, and standard error file associated with it. It is very simple for programs to read input data from the standard input, write results to the standard output and write error messages to the standard error. For interactive shell processes (login sessions) all three files are normally mapped to the terminal. Programs that read from or write to the terminal are actually reading from or writing to the standard input and output.

The program does not know that it is talking to the terminal instead of a file. Because of this, the shell can arrange to re-direct the input, output, or error files (called generally, Input/Output or I/O) to or from the terminal, files on disk, or other peripheral devices (tapes, printers, plotters, etc.). Note that it is the shell which sets up the redirected I/O before starting the program - the program just treats the standard input and output as data streams and does not care from where or to where they are directed.

<--Previous Overview Next-->

Comments or Questions?