Wednesday, April 15, 2009

What is /dev/null on linux

  • The /dev/null on linux is a special file on linux. It is not a directory, it is a file. As it is a file so you can't copy/move something within it.

  • The /dev/null is also called the null device which discards all data written to it, but it shows the operation is successful. For example you can send the ls -l command to /dev/null file and whenever u open the file you will see nothing as it discards everything you write into it but written will be successful. An example is given below.


Normal ls command returns output.
# ls -a t.*
t.t

Redirect output to /dev/null
# ls -a t.* >/dev/null

See the contents of /dev/null
# cat /dev/null

See whether writings to /dev/null is successful.
# ls -a t.* >/dev/null

Return status is 0 which can be seen by $? command and it indicates 0 which means writing is successfully done.
# echo $?
0

  • The /dev/null file provides no data to any process to read from it. If you do it yields end of file (EOF) immediately.

  • The /dev/null file is also called as big bucker or black hole in unix programming.

  • In programming aspect, /dev/null is normally used to write unwanted output. To redirect any unwanted output you can send it to /dev/null.

Related Documents

No comments:

Post a Comment