stdout is a common activity while shell scripting, yet I can never remember how to do it.
Here is a basic summary of file piping in
1> is outputting to
2> is outputting to
> is a shortcut for
1>, and most people remember how to redirect to a file:
command > file -- which means, equivalently,
command 1> file.
stderr to a file is
command 2> stderr.
stdout, you do
2>&1 (conversely, to redirect
stderr, you would do
To redirect both
stdout to a file, then you need to do:
The order is important; if you do
command >file 2>&1
command 2>&1 >file, then
stderrwill be redirected to
stdoutis redirected to the file.
However, this use case is common enough that
2>&1 can be abbreviated as
You only need to really remember how to do this:
command &> file