December 2018
Beginner
452 pages
12h 17m
English
Another special device we can use is /dev/zero. When we redirect output to /dev/zero, it does exactly the same as /dev/null: the data disappears. However, in practice, /dev/null is most often used for this purpose.
So, why have this special device then? Because /dev/zero can also be used to read null bytes. Out of all possible 256 bytes, the null byte is the first: the hexadecimal 00. A null byte is often used to signify the termination of a command, for example.
Now, we can also use these empty bytes to allocate bytes to the disk:
reader@ubuntu:/tmp$ ls -l-rw-rw-r-- 1 reader reader 48 Nov 6 19:26 outputreader@ubuntu:/tmp$ head -c 1024 /dev/zero > allocated-filereader@ubuntu:/tmp$ ls -l-rw-rw-r-- 1 reader reader 1024 Nov 6 20:09 ...