Confusion with the redirection of output to 2>&1?

Viewed 2698

I have checked couple of relevant posts regarding this in stackoverflow and other sources regarding the usage of 2>&1.

Unfortunately so far have not get my head around it completely.

I understand that 2 is the stderr and 1 is the stdout and we are combining with the 2>&1.

But my question is what is difference between:

1. mycommand > /dev/null       
2. mycommand 2> /dev/null      
3. mycommand > /dev/null 2>&1  

I was thinking:

  1. will redirect stdout and stderr to /dev/null
  2. will redirect stderr to /dev/null
  3. will redirect stdout and stderr to /dev/null

Relevant posts:

4 Answers
Related