/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 Code:
ls -l /etc/ | grep resolv.conf > /dev/null 2>&1 |
> 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. |
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. |