next up previous
Next: Pipes Up: Shells Previous: Quoting

Redirection

Output redirection. Output from a program may be redirected to a file using the >, m>, or m>&n operators. m and n refer to file descriptors, where 0 = stdin, 1 = stdout, and 2 = stderr.

eg1$ ls >dir-contents
eg2$ tar cvf backup.tar >tar.log 2>&1
eg3$ find / -name \*.c >find.log 2>/dev/null

Input Redirection. Input to a program may be obtain from a file by using the <, <<TAG operators.

eg1$ xargs pgrep <file-of-files

TIP: Never use cat with a pipe when you could've just redirected. People will laugh at you. e.g.
hip$ somecommand <file
doh$ cat file | somecommand

Finally, redirections can occur anywhere on the line:
sohip$ <file somecommand



Reece Kimball Hart
1998-03-18