The >
command is equivalent to 1>
, which means that the standard output ( standard output - stdout
) is redirected to the indicated file. The 2>
means that the standard error output ( standard error output - stderr
) is being redirected. In addition to 1
and 2
, there is also the 0
that represents the default entry ( stdin
).
In this case, meuComando
is redirecting standard output to /dev/null
; the error output is also being redirected, but not to one file, but to another stream . According to this answer in SOen , the use of &
indicates that the output will go to another file descriptor in>, not to a file. And as seen, the file descriptor 1
represents stdout
.
So, 2>&1
means "redirect stderr
to stdout
". Since stdout
is already redirecting to the "black hole", this will also be done with stderr
. But even if it were not, this command can be useful if you want to send both outputs to the same destination, not each to a different file:
meuComando > saida_e_erros.txt 2>&1