分类: C/C++
2010-10-06 19:28:30
下面的命令显示了用dd命令生成一个200M大小的空文件的全过程:
$dd if=/dev/zero of=./tmp_file bs=100M count=2 &
[1] 4398
$2+0 records in
2+0 records out
209715200 bytes (210 MB) copied,4.34419 秒,48.3 MB/秒
[1]+ Done dd if=/dev/zero of=./tmp_file bs=100M count=2
$ll tmp_file
-rw-r--r-- 1 root root 209715200 01-12 12:42 tmp_file
In , /dev/zero is a that provides as many null characters ( to map /dev/zero to the virtual address space is the way of implementing . NUL, 0x00) as are read from it. One of the typical uses is to provide a character stream for overwriting information. Another might be to generate a clean file of a certain size. Using
Destroy data on a partition
#Do not execute this code on any computer unless you want to destroy all data on a partition!
dd if=/dev/zero of=/dev/hda8
Create a 1 file filled with zeroes called 'foobar'
dd if=/dev/zero of=foobar count=1024 bs=1024
Like /dev/null, /dev/zero acts as a source and sink for data. All writes to /dev/zero succeed with no other effects (the same as for /dev/null, although /dev/null is the more commonly used data sink); all reads on /dev/zero return as many NULs as characters requested.