Multiple redirection

Syntax

command > file 2>&1

Send both the standard output and the standard error of command to file.

command &> file

command >& file

These are the same as command > file 2>&1. The short forms are available in any reasonably recent Bash version. The two forms are equivalent, but we advise use the first one and to avoid the second one.

command | tee [options] file

Send the output of command through a pipe to tee to the standard output, which is usually the terminal, and to file. The option -a appends to the file rather than overwriting it.

command 2>&1 | tee [options] file

Send both the standard output and the standard error of command through a pipe to tee to the standard output, which is usually the terminal, and to file. The option -a appends to the file rather than overwriting it.


2020–07–16