Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Summary of Commands Up: Shell Commands Previous: Filename Completion & Wildcards

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. Another pipe example is

cat text | ispell -h

which would send the contents of text not to the screen, but through a spell checker. The spelling checker will then print out those words in the file text which are not in the online dictionary.


next up previous contents
Next: Summary of Commands Up: Shell Commands Previous: Filename Completion & Wildcards
© Cambridge University Engineering Dept
Information provided by Tim Love
2005-08-22