Department of Engineering

IT Services

Redirection and Pipes

Processes have a standard input channel (stdin), a standard output channel (stdout) and a standard error channel (stderr). By default the keyboard is standard input, and output plus errors go to the screen, but it is one of the strengths of Unix that a process needn't know where its input came from and all the channels can easily be redirected to files. Type date and the date will be shown on screen, but type

date > out

and the output goes into the file called out. You can check this using the command more out which will write the contents of out onto the screen. who is a command which prints out who is logged on to the workstations near to you.

who >> out

(note the double '>' signs) will append the output of who to the file out. Check this again using more (more will display the first page of the file; to see successive pages press the <space> bar). You can also redirect output into another process's input. This is done using the `|' character (found above the <Return> key). Type

date | wc

and the output from date will be `piped' straight into a program that counts the number of lines, words and characters in its input.