Pages

Thursday, 12 January 2017

What does /dev/null 2>&1 mean?

Quite often you will see commands with '/dev/null 2>&1' appended onto them. e.g.

make /dev/null 2>&1

The obvious observation is that the output is being piped into /dev/null i.e. into nothingness!

Although it also appears to pipe out again shortly after.

To help visualise - 0,1,2 all mean something - they are in fact file descriptors:

0 = STDIN (Standard Input)
1 = STDOUT = (Standard Output)
3 = STDERROR (Standard Error)

So the command - as well as piping standard output into /dev/null - also then pipes (with the inclusion of the & symbol)  standard error into file descriptor 1 (stdout) - hence redirecting stderr to stdout - making it visible in the users terminal.

No comments:

Post a Comment