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?
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).
-
1
-
7
-
4I'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.– KonerakJan 31, 2013 at 13:32 -
13@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.– neurinoJan 31, 2013 at 14:06 -
1@Konerak I'm fairly suspicious of that. I've heard it said all over the place and I've never once seen evidence of it being possible on any remotely new harddrive (made in the past 10 years at least).– RobJan 31, 2013 at 16:34
cat -v /dev/zero
to see what it is doing. See Clear unused space with zeros (ext3,ext4) for a common purpose.cat foo > /dev/null
andcat foo > /dev/zero
are the same, butcat /dev/null
andcat /dev/zero
aren't the same, correct?/dev/null
returns immediately EOF if a program wants to read from it./dev/zero
returns infinitely 0-bytes.