# What is /dev/null?



## PowerBookDude (Apr 19, 2002)

I was wondering could someone tell me what /dev/null is?


Thanks!


----------



## Alexandert (Apr 19, 2002)

I was told that it is kind of a "black hole" in the UNIX system. Whatever you put there is gone forever. But where to find of if itd just a joke .......dunno.


----------



## dricci (Apr 19, 2002)

/dev/null

Device 0

It's a blackhole. Nothing exists there, so if you put something there, it goes bye bye for a long long time!


----------



## ladavacm (Apr 19, 2002)

It has a very useful purpose in scripting: in order to discard unwanted (diagnostic or otherwise) output from a command in a shell script, one simply redirects this output to /dev/null.

One example is using grep to see whether a file contains a regex; grep will print the line(s) containing this regex, which may not be needed in the script--one is interested only in yes/no

if grep REGEX file >/dev/null 2>&1; then ...

will do nicely.

/dev/null is also an empty file, and can be used to truncate existing files by copying it on top of them

cp /dev/null file-to-truncate

will in effect make file-to-truncate to be of size zero (even if it previously existed), because it copied an empty file (there are other ways of doing that)


----------



## jocknerd (Apr 22, 2002)

I setup procmail filters to send anything I don't want to /dev/null.


----------

