Why is there a need for /dev/null, /dev/zero and other special device (files) in /dev
I wonder why there is a need that the UNIX and/or Linux developers create /dev/null, /dev/zero and other special device (files) in /dev.
Anyways, Why? |
/dev/null is a place to send things that you NEVER want to see again---e.g. error messages
/dev/zero is a handy place to get a zero---or LOTS of zeros WHY? As with many things in engineering, it could have been the first solution that met the design criteria, and it never had enough issues to motivate anyone to change it. |
Because they are tools that can and are useful.
|
Speaking for myself it's good to know /dev/null is there.
|
Thanks
Hi, Thanks for a fast reply. I have been coding advanced programs for linux and never need to use /dev/null, /dev/zero at all.
|
I use it when I'm putting together a DVD of something, like when I need to extract a video track from a video file I do:
tcextract -x mpeg2 -i file.mpg > file.m2v 2>/dev/null This keeps the process from spitting out bunches of stuff to standard output, meaning the screen, and causing unnecessary curiosity or suspicion on your part. Keeps the screen clean. |
Also
Code:
somecommand > /dev/null 2>&1 |
Quote:
|
Quote:
|
Wouldn't redirect to standard output cause it to show up on the screen? Isn't standard output the screen? I mean what is displayed there? And the ampersand followed by the number 1, I need a clear explanation of what each one means, the ampersand and the number 1. What I DO know is the ampersand can be used at the end of a command line to make it run in the background. I didn't know it could be used for other stuff. Every time I go to the bash user manual I have a devil of a time finding these special symbols. I find them being USED but not an adequate decription of exactly what they are meant to do in each particular situation in which they are used. Another example of what I mean here is the curly bracket, "{" and "}". I know it's used in special cases such as changing certain elements of a bunch of filenames with the inclusion of other symbols such as # ^ but as soon as I learn it I seem to forget. Does that mean I'm too old to learn? I hope not because that would be catastrophic.
|
Quote:
file descriptor 1 is stdout file descriptor 0 is stdin You need to put a & in front of the 1 to tell the redirection to go to file descriptor 1 rather than a file called "1". You're right in that stdout is the screen, however the "> /dev/null" has already redirected stdout to /dev/null. Basically the "2>&1" combines both stdout and stderr on stdout, then the "> /dev/null" throws both of them into the abyss. |
Okay one more thing. Does it matter in which order these are used? I've always seen ">" used before "2>" but does it make a difference if they are used with "2>" before ">" ?
|
Here is a start on redirection:
http://mywiki.wooledge.org/BashFAQ/055 http://www.gnu.org/software/bash/man...l#Redirections |
Because stdout is the default output, its allowed to skip the '1' ie
Code:
prog > t.t You can in fact separate output & errors thus Code:
prog 1>prog.out 2>prog.err |
All times are GMT -5. The time now is 11:51 PM. |