|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 655|回復: 0
打印 上一主題 下一主題

/dev/null和/dev/zero区别

[複製鏈接]

86

主題

3

好友

577

積分

中學生

Rank: 3Rank: 3

  • TA的每日心情
    開心
    2024-10-15 21:32
  • 簽到天數: 1627 天

    [LV.Master]伴壇終老

    推廣值
    0
    貢獻值
    0
    金錢
    7346
    威望
    577
    主題
    86
    樓主
    發表於 2014-11-14 21:41:21
    /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/null:
    In Unix-like operating systems, /dev/null or the null device is a special file that discards all data written to it, and provides no data to any process that reads from it (it returns EOF). In Unix programmer jargon, it may also be called the bit bucket or black hole.
    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.
    This entity is a common inspiration for technical jargon expressions and metaphors 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 PowerBook G4 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 April Fool's, 1995 issue of the German magazine c't reported on an enhanced /dev/null chip that would efficiently dispose of the incoming data by converting it to flicker on an internal glowing LED.
    /dev/null is a special file, not a directory (folder), so one cannot move files into it with the Unix mv command. See rm for the proper way to delete files in Unix.
    The equivalent device in CP/M (and later DOS and Windows) 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 Amiga operating systems, the device's name is NIL:. In Windows NT and its successors, it is named \Device\Null internally, though, the DOS NUL is a symbolic link to it. Similarly, in OpenVMS the device is named NL:.
    /dev/zero:
    In Unix-like operating systems, /dev/zero is a special file that provides as many null characters (ASCII 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 BSD 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.
    zz:http://www.cublog.cn/u/27493/showart_390353.html
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-11-1 10:31 , Processed in 0.021856 second(s), 17 queries , Gzip On, Memcache On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部