[an error occurred while processing this directive]

Unix File Redirection and Piping Redirection

Unix commands can be strung together to form a powerful assembly line. When commands are involved, the process is called "piping." When files are involved, it's called "redirection." Commands covered are: The file redirection facility in Unix allows a program to access a single input file and a single output file very easily. The program is written to read from the keyboard and write to the terminal screen as normal. The program is run slightly differently in order to access files for input and output.

To run prog1 but read data from file infile instead of the keyboard, you would type


  prog1 < infile
To run prog1 and write data to outfile instead of the screen, you would type

  prog1 > outfile
Both can also be combined as in

  prog1 < infile > outfile

Redirection is simple to achieve, and has the advantage that the same program can be used to read or write data to or from files or the screen and keyboard.

Some programs require several files to be used for input or output, and redirection cannot do this. In such cases you will have to use C's file handling facilities. [an error occurred while processing this directive]

Monday, 31-Mar-1997 19:55:08 EST