LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   /dev/null 2>&1 ??????????? (https://www.linuxquestions.org/questions/linux-general-1/dev-null-2-and-1-a-554723/)

waelaltaqi 05-17-2007 04:10 PM

/dev/null 2>&1 ???????????
 
i know that /dev/null is used redirect output of commands in shell scripts to a null device so the user won't see a lot of output when running certain scripts.
here is my question: what is the difference between these two command?
Code:

ls -l /etc | grep resolv.conf > /dev/null
and
Code:

ls -l /etc/ | grep resolv.conf > /dev/null 2>&1
i just want to understand what 2>&1 means.

acid_kewpie 05-17-2007 04:23 PM

> redirects the stdout stream, same as 1> as 1 is the number of that stream. 2 is the stderr stream. 2>&1 causes stderr to be redirected into stdout and then sunk into /dev/null, otherwise whilst all normal output disappears, any errors (e.g ls command not found, resolv.conf not allowd to be opened) would still show up. in the longest form you could write....

ls -l /etc/ | grep resolv.conf 1> /dev/null 2> /dev/null

but oviosuly, that's longer hence shortcuts and such.

waelaltaqi 05-17-2007 10:22 PM

after reading your reply and http://en.wikipedia.org/wiki/Redirection_%28Unix%29 i understand now why it's very commonly used. Otherwise, a lot of scripts will show a whole load of errors.
thanks.


All times are GMT -5. The time now is 12:59 PM.