Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1375612
  • 博文数量: 244
  • 博客积分: 10311
  • 博客等级: 上将
  • 技术积分: 3341
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-14 21:50
文章分类

全部博文(244)

文章存档

2013年(6)

2012年(5)

2011年(16)

2010年(11)

2009年(172)

2008年(34)

分类: LINUX

2009-05-19 20:54:22

 

/dev/null,外号叫无底洞,你能向他输出所有数据,他通吃,并且不会撑着!
/dev/zero,是个输入设备,你可你用他来初始化文件。

/dev/null------他是空设备,也称为位桶(bit bucket)。所有写入他的输出都会被抛弃。如果不想让消息以标准输出显示或写入文件,那么能将消息重定向到位桶。
/dev/zero------该设备无穷尽地提供0,能使用所有你需要的数目??设备提供的要多的多。他能用于向设备或文件写入字符串0。

oracle@localhost oracle]$if=/dev/zero of=./test.txt bs=1k count=1
oracle@localhost oracle]$ ls -l
total 4
-rw-r--r-- 1 oracle dba       1024 Jul 15 16:56 test.txt

eg,

find / -name access_log   2>/dev/null

这样,一些诸如一些错误信息就不会显示出来。

在目录/dev下有两个特殊的设备文件:/dev/null和/dev/zero。它们并不是真实的设备文件,那它们是什么?它们有什么区别?我在自己的blog上做个记录。

下面关于它们的内容来自于维基百科。

关于/dev/null:

In , /dev/null or the null device is a special file that discards all data written to it, and provides no data to any that reads from it (it returns ). In jargon, it may also be called the or black hole.

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

This entity is a common inspiration for technical expressions and by Unix programmers, e.g. "please send complaints to /dev/null" or "my mail got archived in /dev/null", being jocular ways of saying, respectively: "don't bother to send any complaints" and "my mail got deleted". A famous advertisement for the Titanium read [The Titanium Powerbook G4] Sends other UNIX boxes to /dev/null.

The null device is also a favorite subject of technical jokes, such as warning users that the system's /dev/null is already 98% full. The , issue of the magazine reported on an enhanced /dev/null that would efficiently dispose of the incoming data by converting it to flicker on an internal glowing .

/dev/null is a special file, not a (folder), so one cannot move files into it with the Unix command. See for the proper way to delete files in Unix.

The equivalent device in (and later and ) is called NUL:, and on some versions of DOS just NUL (for example, one may hide output by directing it to NUL, e.g. PAUSE>NUL, which waits for the user to press any key without printing anything to the screen). Under classic operating systems, the device's name is NIL:. In and its successors, it is named \Device\Null internally, though, the DOS NUL is a to it. Similarly, in the device is named NL:.

关于/dev/zero:

In , /dev/zero is a special file that provides as many null characters ( NULL, 0x00; not ASCII character "digit zero", "0", 0x30) 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 mmap to map /dev/zero to RAM is the way of implementing shared memory.

# Initialise partition (important note: trying out this command will eradicate 
# any files that were on the partition, make sure you have a backup of any important data.)
dd if=/dev/zero of=/dev/hda7
# Create a large empty file called 'foobar'
dd if=/dev/zero of=foobar count=1000 bs=1000

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.

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