As already stated, such files are either files 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 contents of the floppy were read. The second time you executed the command, there was no access to the floppy drive at all. This is because the contents of the floppy were 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.
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/hda /dev/lp0 brw-rw---- 1 root disk 3, 0 May 5 1998 /dev/hda crw-rw---- 1 root daemon 6, 0 May 5 1998 /dev/lp0 |
Here, the major and minor of /dev/hda are 3 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 3 and minor 0 (this file actually exists: /dev/ttyp0), 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 do not handle a floppy drive the same way as, say, a SCSI hard drive.