The command >
is equivalent to 1>
, and means you’re redirected to standard output (standard output - stdout
) to the specified file. Already the 2>
means that one is redirecting the standard error output (standard error output - stderr
). Beyond the 1
and of 2
, there is also the 0
representing the standard input (stdin
).
In that case, meuComando
is redirecting the standard output to /dev/null
; error output is also being redirected, but not to one file, but to another stream. According to that answer in Soen, the use of &
indicates that the output will go to another file Descriptor, and not to a file. And as seen, the file Descriptor 1
represents the stdout
.
Therefore, 2>&1
means "redirect the stderr
to the stdout
". Like the stdout
is already redirecting to the "black hole", this will also be done with the stderr
. But even if it wasn’t, this command can be useful if you want to send both outputs to the same destination, not each one to a different file:
meuComando > saida_e_erros.txt 2>&1
Related: http://answall.com/questions/52622/ (or dup?)
– bfavaretto
@bfavaretto I had not seen this, but the question itself focuses on a different instruction from this... I think the two questions can coexist!
– Zuul
Also related: http://answall.com/questions/40254/comond-messagingpara-stderr-no-bash-via-command echo
– bfavaretto