Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1364418
  • 博文数量: 704
  • 博客积分: 10140
  • 博客等级: 上将
  • 技术积分: 6230
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-15 20:41
文章分类

全部博文(704)

文章存档

2013年(1)

2012年(16)

2011年(536)

2010年(151)

分类: C/C++

2010-10-06 19:28:30

/dev/null,外号叫无底洞,你可以向它输出任何数据,它通吃,并且不会撑着!
/dev/zero,是一个输入设备,你可你用它来初始化文件。
/dev/null------它是空设备,也称为位桶(bit bucket)。任何写入它的输出都会被抛弃。如果不想让消息以标准输出显示或写入文件,那么可以将消息重定向到位桶。
/dev/zero------该设备无穷尽地提供0,可以使用任何你需要的数目——设备提供的要多的多。他可以用于向设备或文件写入字符串0。

/dev/zero的两个主要用途:
1)    用来创建一个指定长度用于初始化的空文件,就像临时交换文件。
2)   另一个应用是为特定的目的而用零去填充一个指定大小的文件, 如挂载一个文件系统到环回设备 (loopback device) 或"安全地" 删除一个文件。

下面的命令显示了用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

下面两段关于/dev/null和/dev/zero的e文很好地阐述了二者的区别
摘自http://hi.baidu.com/ark803/blog/item/f914899505acf30e7bf48095.html
/dev/null
In Unix-like operating systems, /dev/null or the null device is a special file that discards all data written to it (but reports that the write operation succeeded), and provides no data to any process that reads from it (yielding EOF immediately)

The null device is typically used for disposing of unwanted output streams of a process, or as a convenient empty file for input streams. This is usually done by redirection.

/dev/null is a special file, not a directory, so one cannot move files into it with the Unix mv command. The rm command is the proper way to delete files in Unix.

/dev/zero

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.

阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~