Hurriyet

20 Ocak 2015 Salı

Linux / Unix : /dev/null Error Redirection and Other /dev files


What is the usage of " command  > /dev/null 2>&1"?

/dev/null  is  a file which takes the input and doesn't print anything in return. /dev/null is kind of a garbage which doesn't have a limit. Therefore we could send anykind of error message in it and not be bothered.

"2" is the STDERR which is standard errors.
"1" is the STDOUT which is standard output.

We have 3 kind of output showed in the screenshot below.

find . -name scripts 2>&1: This command has the purpose of searching a file or folder named scripts. it also tells that all the errors to be showed in the screen


find . -name scripts 2>/dev/null: In here we are sending all the errors to our garbage. With this command we are preventing any kind of errors to be showed in the screen.

find . -name scripts > /dev/null 2>&1: This command all together stops printing the messages on the screen.



What else are there besides /dev/null ?

There are a whole lot of files besides it. Our Reference-1 tells all about it. But we can say that /dev/null is the most used one.




References:
1- /dev files - http://www.linux.org/threads/what-are-those-dev-files.4713/

2-  Standard output - http://www.codecoffee.com/tipsforlinux/articles2/042.html

Hiç yorum yok:

Yorum Gönder