| by Arround The Web | No comments

Q&A trip to Linux’s Black Hole – /dev/null

Q&A trip to Linux’s Black Hole - /dev/null

As per NASA, “A black hole is a place in space where gravity pulls so much that even light can not get out”. Something similar exists in the Linux universe as well - it discards anything written to it and when read, just returns an EOF (end-of-file). It’s a special file which is also referred to as null device - /dev/null

So, it’s just a file?

Yes and most of the things in Linux is a file but /dev/null is not a regular file – lets dig deeper.

/dev/null 1

c in crw-rw-rw- tells us that it's a character special file, which means it processes data character by character. This can be checked using test -c as well:

/dev/null 2

What are the contents of the file?

Let’s check that using the cat command:

/dev/null 3

As stated earlier, it just returns an EOF (end-of-file) when read. So, it's empty!

What more can we know about the file?

Let’s find out using the stat command:

/dev/null 4

This tells us that its size is 0. Also, it’s good to note that the file’s read and write permission is enabled for everyone but it doesn't require execute permission. 

What happens to the file’s size when we write data to it?

Let’s try that:

/dev/null 5

The cat command returned nothing and as per the stat command, its size did not change.

As stated earlier, it discards anything written to it. You may write any amount of data to it, which will be immediately discarded, so its size will always remain 0 – Singularity?

In other words, you cannot change /dev/null

Is it useful? How to use it?

Share Button

Source: Linux Journal - The Original Magazine of the Linux Community

Leave a Reply