As already stated, such files are either created by the system or peripherals on your machine. We also mentioned that the contents of block mode character files were buffered, while character mode files were not. In order to illustrate this, insert a floppy into the drive and type the following command twice:
$ dd if=/dev/fd0 of=/dev/null
You should have observed the following: the first time the command was launched, the entire content of the floppy was read. The second time you executed the command, there was no access to the floppy drive at all. This is because the content of the floppy was buffered the first time you launched the command — and you did not change anything on the floppy between the two instances.
But now, if you want to print a big file this way (yes it will work):
$ cat /a/big/printable/file/somewhere >/dev/lp0
The command will take as much time, whether you
launch it once, twice or fifty times. This is because
/dev/lp0
is a character mode file, and its contents
are not buffered.
The fact that block mode files are
buffered has a nice side effect: not only are reads buffered, but writes
are buffered too. This allows for writes to the disks to be asynchronous:
when you write a file on disk, the write operation itself is not
immediate. It will only occur when the Linux kernel decides
to execute the write to the hardware. Of course, if you need it
can be overridden for a certain filesystem; take a look at the
sync
and async
options at the
mount(8) man page and also at Section 7, “File Attributes” for more details.
Finally, each special file has a major and minor number. On a ls -l output, they appear in place of the size, as the size for such files is irrelevant:
$ ls -l /dev/hdc /dev/lp0 brw-rw---- 1 queen cdrom 22, 0 Feb 23 19:18 /dev/hdc crw-rw---- 1 lp sys 6, 0 Feb 23 19:17 /dev/lp0
Here, the major and minor of
/dev/hdc
are 22 and 0,
whereas for /dev/lp0
, they are 6 and 0. Note
that these numbers are unique per file category, which means that there
can be a character mode file with major 22 and minor 0, and similarly, there can be a
block mode file with major 6 and minor 0. These numbers exist for a simple
reason: it allows the kernel to associate the correct operations to these
files (that is, to the peripherals these files refer to): you don't handle
a floppy drive the same way as, say, a SCSI hard drive.