Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried to cat /dev/zero, and it didn't seem to do anything. I googled /dev/zero, and it says it's basically a blank file with infinite size. Is cat printing an infinite number of non-existent characters? How does this work? How does it provide infinite data if it's 0 bytes? What are the uses of this file, if one can simply create a blank file?

share|improve this question
Run cat -v /dev/zero to see what it is doing. See Clear unused space with zeros (ext3,ext4) for a common purpose. –  manatwork Jan 31 '13 at 13:09
There is also /dev/null which behaves like an empty file if you want to read it and as a black hole if you write to it. –  jofel Jan 31 '13 at 15:00
@jofel but you can't use /dev/null for infinite 0-bits, right? cat foo > /dev/null and cat foo > /dev/zero are the same, but cat /dev/null and cat /dev/zero aren't the same, correct? –  tkbx Jan 31 '13 at 15:19
@tkbx yes, correct. /dev/null returns immediately EOF if a program wants to read from it. /dev/zero returns infinitely 0-bytes. –  jofel Feb 1 '13 at 11:04
add comment

1 Answer

/dev/zero is a special file (in this case, a pseudo-device) that provides an endless stream of null characters (so hex 0x00)? That's why your cat is not outputting anything (but try running it through od (octal dump)).

'blank file with infinite size' is not 100% correct: it's not a regular file, but a special file (more like a 'stream' or a generator). You can read as much from it as you want, for example with dd (like dd if=/dev/zero of=yourfile count=1024 bs=1024).

It's not really a blank file, nor used to create blank files: it's used to create files or memory pages filled with only zeroes. You can also write to it, making it perform like a sinkhole (its more popular brother /dev/null is more commonly used for this though).

share|improve this answer
Why would someone want to fill up blank space, though? –  tkbx Jan 31 '13 at 13:16
For example, to erase what was there before. Or when transmitting. –  Konerak Jan 31 '13 at 13:18
does srm use this? –  tkbx Jan 31 '13 at 13:28
I've not read the srm manual or source, but most 'secure erasers' prefer to write (pseudo-)random data instead of zero-ing a drive, since one pass of zero-ing is not secure enough (certain three-letter agencies can still deduct the original contents of a zeroed harddisk, since the individual bits are not 100% truly 1 or 0, but just "mostly 1" or "mostly 0". Compare it to a lever which you can put "all the way left" or "all the way right", but usually just a swing to the other side is enough. –  Konerak Jan 31 '13 at 13:32
@tkbx trying to dd a partition you may want to fill all empty space to 0 rather than random to get a smaller compressed file later. –  neurino Jan 31 '13 at 14:06
show 5 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.