back toc next

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
command >&2                      # redirect stdout to stderr
command 2>&1                     # redirect stderr to stdout

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