Redirection#
The order of redirection matters because the shell processes them from left to right.
> /dev/null 2>&1 vs 2>&1 > /dev/null#
1. > /dev/null 2>&1#
Both stdout and stderr are suppressed.
> /dev/null: Redirects stdout to/dev/null.2>&1: Redirects stderr to the current location of stdout (which is now/dev/null).
2. 2>&1 > /dev/null#
Only stdout is suppressed; stderr is still printed to the terminal.
2>&1: Redirects stderr to the current location of stdout (the terminal).> /dev/null: Redirects stdout to/dev/null.
&>#
A Bash shortcut to redirect both stdout and stderr to the same destination. &> <file> is equivalent to > <file> 2>&1.
eg. $ ls <file> &> /dev/null