Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [48]

By Root 2629 0
system, you may still find symbolic link fossils from the usrzoic era.

Home directories of users should be kept on a separate filesystem, usually mounted in the root directory or occasionally beneath /usr. Separate filesystems can also be used to store bulky items such as source code libraries and databases.

Some of the more important standard directories are listed in Table 5.1 (some rows have been shaded to improve readability).

Table 5.1 Standard directories and their contents

a. Where /sbin is present, /bin is usually a symbolic link to /usr/bin.

5.4 FILE TYPES


Most filesystem implementations define seven types of files. Even if you are adding something new and wonderful to the file tree (such as the process information listed under /proc), it must still be made to look like a collection of these seven types:

• Regular files

• Directories

• Character device files

• Block device files

• UNIX domain sockets

• Named pipes (FIFOs)

• Symbolic links

A few systems do not support UNIX domain sockets or named pipes.

Regular files


A regular file is just a bag o’ bytes; UNIX imposes no structure on its contents. Text files, data files, executable programs, and shared libraries are all stored as regular files. Both sequential and random access are allowed.

Directories


A directory contains named references to other files. You can create directories with mkdir and delete them with rmdir if empty. You can delete nonempty directories with rm -r.

The special entries “.” and “..” refer to the directory itself and to its parent directory; they may not be removed. Since the root directory has no parent directory, “..” there is the same as “.”.

A file’s name is actually stored within its parent directory, not with the file itself. In fact, more than one directory (or more than one entry in a single directory) can refer to a file at one time, and the references can have different names. Such an arrangement creates the illusion that a file exists in more than one place at the same time.

These additional references (“links”) are indistinguishable from the original file; as far as UNIX is concerned, they are equivalent. UNIX maintains a count of the number of links that point to each file and does not release the file’s data blocks until its last link has been deleted. Links cannot cross filesystem boundaries.

References of this sort are usually called “hard links” these days to distinguish them from symbolic links, which are described below. You create hard links with ln and remove them with rm.

It’s easy to remember the syntax of ln if you keep in mind that it mirrors that of cp. The command cp oldfile newfile creates a copy of oldfile called newfile, and ln oldfile newfile makes the name newfile an additional reference to oldfile.

It is important to understand that hard links are not a distinct type of file. Instead of defining a separate “thing” called a hard link, the filesystem simply allows more than one directory entry to point to a particular file. The underlying attributes of the file, such as ownerships and permissions, are shared among all links.

Character and block device files


Device files allow UNIX programs to communicate with the system’s hardware and peripherals. When the kernel is configured, modules that know how to communicate with each of the system’s devices are linked in.3 The module for a particular device, called a device driver, takes care of the messy details of managing the device.

See Chapter 12 for more information about devices and drivers.

Device drivers present a standard communication interface that looks like a regular file. When the kernel is given a request that refers to a character or block device file, it simply passes the request to the appropriate device driver. It’s important to distinguish device files from device drivers, however. The files are just rendezvous points that are used to communicate with the drivers. They are not the drivers themselves.

Character device files allow their associated drivers to do their own

Return Main Page Previous Page Next Page

®Online Book Reader