What Does "2>&1" Do in Command Line?

What Does "2>&1" Do in Command Line?

I know that the > sign is used for output redirection in the command line, but I'm having trouble finding something that explains the use of 2>&1 in the command line. For example:

curl  > /dev/null 2>&1 &
1

4 Answers

The 1 denotes standard output (stdout). The 2 denotes standard error (stderr).

So 2>&1 says to send standard error to where ever standard output is being redirected as well. Which since it's being sent to /dev/null is akin to ignoring any output at all.

10

tl;dr

Fetch in the background and discard both the stdout and stderr.

curl > /dev/null 2>&1 &

is the same as

curl > /dev/null 2>/dev/null &

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.