/ linux

bash redirection for noobs

From time to time it's helpful to collect (and discard) all output from stdout & stderr after a magic bash command prints something.

Could be like

$ magic_command > /dev/null 2>&1


==> All output of the magic_command will be redirected to /dev/null, included is 2-StdErr and 1-StdOut:

> is for redirect

/dev/null is the black magic hole where any sent data discards

2 is the handle/filedescriptor for StdErr

> is again for redirect

& is the symbol for the file descriptor (with, the following txt is considered as filename)

1 is the handle/filedescriptor for StdOut