/dev/nullThis is the null device. All (Com web hosting) output written
Friday, August 31st, 2007/dev/nullThis is the null device. All output written to this device is discarded. An immediate end of file isreturned when the device is read, and it can be used as a source of empty files by using the cpcom- mand. Unwanted output is often redirected to /dev/null. $ echo do not want to see this >/dev/null$ cp /dev/null empty_fileOther devices found in /devinclude hard and floppy disks, communications ports, tape drives, CD-ROMs, sound cards, and some devices representing the system s internal state. There s even a/dev/zero, which acts as a source of nullbytes to create files of zeros. You need superuser permissionsto access some of these devices; normal users can t write programs to directly access low-level deviceslike hard disks. The names of the device files may vary from system to system. Linux distributions usu- ally have applications that run as superuser to manage the devices that would be otherwise inaccessible, for example, mountfor user-mountable file systems. Devices are classified as either character devicesor block devices. The difference refers to the fact that somedevices need to be accessed a block at a time. Typically, the only block devices are those that supportsome type of random access file system, like hard disks. In this chapter, we concentrate on disk files and directories. We ll cover another device, the user s termi- nal, in Chapter 5. System Calls and Device DriversWe can access and control files and devices using a small number of functions. These functions, knownas system calls, are provided by UNIX (and Linux) directly, and are the interface to the operating systemitself. At the heart of the operating system, the kernel, are a number of device drivers. These are a collection oflow-level interfaces for controlling system hardware, which we will cover in detail in Chapter 18. Forexample, there will be a device driver for a tape drive, which knows how to start the tape, wind it for- ward and backward, read and write to it, and so on. It will also know that tapes have to be written toinblocks of a certain size. Because tapes are sequential in nature, the driver can t access tape blocksdirectly, but must wind the tape to the right place. Similarly, a low-level hard disk device driver will only write whole numbers of disk sectors at a time, but will be able to access any desired disk block directly, because the disk is a random access device. To provide a similar interface, device drivers encapsulate all of the hardware-dependent features. Idiosyncratic features of the hardware are usually available through ioctl. Another way of creating empty files is to use the touch