Device Files

Device files refer to physical or virtual devices on your system,

such as your hard disk, video card, screen, and keyboard. An example

of a virtual device is the console, represented by /dev/console.

There are two kinds of devices:character and block. _Character

devices_ can be accessed one character at a time. Remember the

smallest unit of data that can be written to or read from the device

is a character (byte).

_Block devices_ must be accessed in larger units called blocks,

which contain a number of characters. Your hard disk is a block

device.

You can read and write device files just as you can from other kinds

of files, though the file may well contain some strange

incomprehensible-to-humans gibberish. Writing random data to these

files is probably a bad idea. Sometimes it’s useful, though. For

example, you can dump a postscript file into the printer device

/dev/lp0 or send modem commands to the device file for the

appropriate serial port.

/dev/null

/

/

/

/dev/null is a special device file that discards anything you write

/to it.

If you don’t want something, throw it in /dev/null. It’s essentially

a bottomless pit. If you read /dev/null, you’ll get an end-of-file

(EOF) character immediately. /dev/zero is similar, except that you

read from it you get the \0 character (not the same as the number

zero).

Debian GNU/Linux : Guide to Installation and Usage · 第 154 / 193 题