Linux /dev/null Explanation
Linux mainly works over files and input output operations. All connected devices are shown in the
null is interesting device which is just nothing. In this tutorial we will look what
/dev/null is and used for.
As stated previously
null is just empty device which is like a bucket with a hole in the bottom. This may be seem a little bit nonsense but the use cases proves that it is useful. Think about that we have a lot of data we should write somewhere but we do not need this data. We can use
null device without a problem.
/dev/null generally used to redirect unneeded or removal intended data. This makes things more elegant. Look following example we create nonsense data and redirect it to the
$ dd bs=1024 count=1000 if=/dev/random of=/dev/null
Another useful case for
null usage is redirecting errors to the
/dev/null . In this example we will redirect errors produced by
ls command to the
/dev/null. We can express error with
2> like below.
$ ls 2> /dev/null
Redirect Standard Output
Another useful redirect example is redirecting standard output to the
null. If we want to test something and only see the errors in the terminal we can redirect standard output to the null and see only errors in the console like below. In this example we will use
wget command to download something and only see errors if happens. We express standard output with
$ wget 1> /dev/null
Type Of Null
Everything in Linux is file. So
/dev/null is also a file. We can get the file type with
file command like below.
null is a character special file type.
$ file /dev/null
Size Of /dev/null
null can eat all data we provide but what is the size of the
null . 1Gb or 100gb no it is just 1 byte as we can see below. It is like an obese but very slim.
$ ls -lh /dev/null