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 –
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.
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:
What are the contents of the file?
Let’s check that using the
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
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:
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