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 since Bash version 4. 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.
Example
command >/dev/null 2>&1
Firstly the standard error (2) is redirected to the standard output (1), then both are redirected to /dev/null to the “null device”, i.e. they are discarded. Any output from command thus is silenced.
2025-12-27
|