Difference between /dev/null and /dev/zero files 

On Linux/UNIX, /dev/zero and /dev/null are two pseudo files which are useful for creating empty files or using as garbage file. Many people consider there is no difference or puzzled with what could be the difference between two files. There is considerable difference when writing data using these hardware files.


/dev/zero: This file is used to create a file with no data but with required size(A file with all zero’s). In other words this will create a data file with all zeros in the file which will give the size to a file.

For example:

Create a file with /dev/zero file

dd if=/dev/zero of=/opt/abc.txt bs=4096 count=1000

it creates a file that has continuous zeros in it.
So we conclude that /dev/zero is a file use full for creating a file with some required size without any meaning to the data.

/dev/null: This is one more Pseudo file which is useful in many places like redirecting unwanted output/error etc to this file. This file acts as a black hole(Which eat up everything and do not show any output). So whenever you feed some data to this file, you can not retrieve the data which is fed to it. This file even useful for creating files with zero size.

Example:

Use /dev/zero as source, write into /dev/null

dd if=/dev/zero of=/dev/null bs=512 count=10
10+0 records in
10+0 records out
5120 bytes (5.1 kB) copied, 8.926e-05 s, 57.4 MB/s

Read back to a file

dd if=/dev/null of=/tmp/read.out bs=512 count=10
0+0 records in
0+0 records out
0 bytes (0 B) copied, 4.506e-05 s, 0.0 kB/s

Nothing comes out !

Now you can see the difference between /dev/null and /dev/zero.