next up previous contents
Next: The HELP System Up: UNIX Previous: Define Current (working) Directory   Contents

Redirecting Input and Output

Most UNIX commands take their input from ``standard input'' and direct their output to ``standard output''. By default the standard input is the user's keyboard and the standard output is the user's screen. Either or both of these can be redirected to a file by using the characters $<$ (redirect input) and $>$ (redirect output. So, if x is a UNIX command:-

x $<$ f1 $>$ f2
would execute the command which would take its input from file f1 and write its output to file f2.

The output from a command can be used to provide the input to another command, so chaining the two commands together. This is called piping. The symbol $\vert$ is used to separate the two commands. Consider:-

ls * | sort
This creates a directory listing but passes the output directly to the sort command. The sort command sorts its input into alphabetical order and outputs the result. The output from the second command could be piped to a third and so on. In this way simple commands can be bolted together in a powerful way.


next up previous contents
Next: The HELP System Up: UNIX Previous: Define Current (working) Directory   Contents
P.D. Gronbech (IT Staff) 2015-10-02