Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [46]

By Root 2735 0
characters long, and a single path may not contain more than 1,023 characters. To access a file with a pathname longer than this, you must cd to an intermediate directory and use a relative pathname.2

There are essentially no restrictions on the naming of files and directories, except that names are limited in length and must not contain the “/” character or nulls. In

particular, spaces are permitted...kind of. Because of UNIX’s long tradition of separating command-line arguments at whitespace, legacy software tends to break when spaces appear within filenames.

Given the amount of file sharing among different types of systems these days, it’s no longer safe to assume that filenames will not contain spaces. Even if you don’t share files with Macs and PCs, there are plenty of users in the habit of typing them. Any scripts you write that deal with the filesystem must be prepared to deal with spaces.

In general, spaceful filenames just need to be quoted to keep their pieces together. For example, the command

% more "My excellent file.txt"

Would preserve My excellent file.txt as a single argument to more.

5.2 MOUNTING AND UNMOUNTING FILESYSTEMS


The filesystem is composed of smaller chunks—also called filesystems—each of which consists of one directory and its subdirectories and files. It’s normally apparent from context which type of “filesystem” is being discussed, but for clarity, we will use the term “file tree” to refer to the overall layout of the filesystem and reserve the word “filesystem” for the chunks attached to the tree.

Most filesystems are disk partitions, but as we mentioned earlier, they can be anything that obeys the proper API: network file servers, kernel components, memory-based disk emulators, etc.

Filesystems are attached to the tree with the mount command. mount maps a directory within the existing file tree, called the mount point, to the root of the newly attached filesystem. The previous contents of the mount point become inaccessible as long as another filesystem is mounted there. Mount points are usually empty directories, however.

For example,

# mount /dev/sd1c /users

would install the filesystem stored on the disk partition represented by /dev/sd1c under the path /users. You could then use ls /users to see the filesystem’s contents.

A list of the filesystems that are customarily mounted on a particular system is kept in the /etc/fstab, /etc/vfstab, or /etc/checklist file, depending on the OS. The information contained in this file allows filesystems to be checked (fsck -p) and mounted (mount -a) automatically at boot time. It also serves as documentation for the layout of the filesystems on disk and enables short commands such as mount /usr; the location of the filesystem to mount is looked up in fstab. See page 133 for a complete discussion of the fstab file and its brethren.

Filesystems are detached with the umount command. On most systems, you cannot unmount a filesystem that is busy. There must not be any open files or processes whose current directories are there, and if the filesystem contains executable programs, they cannot be running.

FreeBSD allows umount -f, which forces a busy filesystem to be unmounted. This is not usually a good idea because the programs that are using it may become quite confused (and crash). Use the -f option at your own risk.

Solaris 8 also provides umount -f, although it’s possible to achieve the same effect under earlier Solaris releases through a two-step process. First, run lockfs -h dir on the mount point to “hard lock” the filesystem. You can then umount it normally.

If the kernel complains that a filesystem you are trying to unmount is busy, you can run the fuser command on most systems to find out why. When invoked in the form fuser -c mountpoint, fuser prints out the PID of every process that’s using a file or directory on that filesystem, plus a series of letter codes that show what’s being done with the files. For example,

% fuser -c /usr

/usr: 157tm 315ctom 474tom 5049tom 84tm 496ctom

490tm 16938c 16902ctm 358ctom

Return Main Page Previous Page Next Page

®Online Book Reader