Redirection
command < file # read input for command from file
command > file # write output of command to file
command >> file # append output of command to file
- every process has one input pipe (stdin) and two output pipes (stdout and stderr)
- every input/output channel is identified by one number:
0 for stdin
1 for stdout
2 for stderr
command >&2 # redirect stdout to stderr
command 2>&1 # redirect stderr to stdout
- redirections are performed by the Shell, before the command is executed
- redirections are performed in order
Examples:
make 2>&1 >file # wrong, if you wanted do redirect both stdout and stderr to file.
make >file 2>&1 # this is what you probably want
sort <file >file # wrong! This is a good way to destroy your data.
sort <file >file.out ; mv file.out file # this is the way to go