In order to make the most effective use of your Linux system, you must understand how Linux organizes data. If you’re familiar with Windows or another operating system, you’ll find it easy to learn how Linux organizes data, because most operating systems organize their data in similar ways. This section explains how Linux organizes data and introduces you to several important Linux commands that work with directories and files.
Linux receives data from, sends data to, and stores data on devices . A device generally corresponds to a hardware unit, such as a keyboard or serial port. However, a device may have no hardware counterpart: the kernel creates several pseudodevices that you can access as devices but that have no physical existence. Moreover, a single hardware unit may correspond to several devices. For example, Linux defines each partition of a disk drive as a distinct device. Table 4-1 describes some typical Linux devices; not every system provides all these devices and some systems provide devices not shown in the table. The device name often appears in messages and filenames on the system.
Table 4-1. Typical Linux devices
Whether you’re using Windows or Linux, you must format a partition before you can store data on it. The installation procedure automatically formats the partitions you create during system installation. When Linux formats a partition, it writes special data, called a filesystem, on the partition. The filesystem organizes the available space and provides a directory that lets you assign a name to each file , which is a set of stored data. A filesystem also enables you to group files into directories , which function much like the folders you create using the Windows Explorer: directories store information about the files they contain.
Just as every partition must have a filesystem, every CD-ROM and floppy diskette must have a filesystem. The filesystem of a CD-ROM is written when the disk is created; the filesystem of a floppy diskette is rewritten each time you format it.
Windows 98 lets you choose to format a partition as a
FAT or FAT32. Windows NT/2000 also
support the NTFS filesystem type. Linux supports a wider variety of
filesystem types; Table 4-2 summarizes the most
common ones. The most important filesystem types are
, which is used for Linux native
which is used for FAT partitions (and floppy diskettes) of the sort
created by MS-DOS and Microsoft Windows; and
, which is used for CD-ROMs. Linux
also provides the
filesystem, which is used for FAT32
partitions of the sort created by Windows 9x.
Linux also supports reading of Windows NT/2000 NTFS filesystems;
however, the support for doing so is not enabled in the standard Red
Hat Linux kernel.
Table 4-2. Common filesystem types
The predecessor of the ext3 filesystem; supported for compatibility.
The standard Linux filesystem.
The standard filesystem used on CD-ROMs.
A filesystem compatible with Microsoft’s FAT filesystem, used by MS-DOS and Windows.
A filesystem compatible with Sun’s Network File System. An nfs filesystem does not reside on a physical partition; it is accessed via the network.
A Linux filesystem designed for high-reliability, large-capacity storage systems.
A filesystem compatible with Microsoft’s FAT32 filesystem, used by Windows 9x.
If you’ve used MS-DOS, you’re familiar with the concepts of file and directory and with various MS-DOS commands that work with files and directories. Under Linux, files and directories work much as they do under MS-DOS.
When you log in to Linux, you’re placed in a special directory known as your home directory. Generally, each user has a distinct home directory, where the user creates personal files. This makes it simple for the user to find files previously created, because they’re kept separate from the files of other users and system files.
The current directory—or current working directory, as it’s sometimes called—is the directory you’re currently working in. When you log in to Linux, you’re automatically placed in your home directory.
The directories of a Linux system are organized as a hierarchy.
Unlike MS-DOS, which provides a separate hierarchy for each
partition, Linux provides a single hierarchy that includes every
partition. The topmost directory of the directory tree is the
root directory, which is written using a forward
/), not the backward slash
\) used by MS-DOS to designate a root
Figure 4-1 shows a hypothetical Linux directory
tree; a real Linux system contains many more directories. The root
directory contains six
/home directory has two subdirectories; each is
the home directory of a user and has the same name as the user who
owns it. The user named
bill has created two
subdirectories in his home directory:
school. The user named
patrick has created the single
subdirectory in his home directory.
Each directory (other than the root directory) is contained in a
directory known as its parent directory. For example, the parent
directory of the
bill directory is
If you look closely at Figure 4-1,
you’ll see that two directories named
school exist; one is a subdirectory of
bill and the other is a subdirectory of
patrick. To avoid confusion that could result
when several directories have the same name, directories are
There are two kinds of pathnames:
The absolute pathname of a directory traces the location of the
directory beginning at the root directory; you form the pathname as a
list of directories, separated by forward slashes
). For example, the
absolute pathname of the unique directory named
/home/bill. The absolute pathname
school subdirectory of the
absolute pathname of the identically named
subdirectory of the
When a subdirectory is many levels below the root directory, its
absolute pathname may be long and cumbersome. In that case, it may be
more convenient to use a relative pathname, which uses the current
working directory, rather than the root directory, as its starting
point. For example, suppose that the
directory is the current working directory; you can refer
books subdirectory by the relative
books. A relative pathname must never
begin with a forward slash, whereas an absolute pathname must begin
with a forward slash. As a second example, suppose that the
/home directory is the current working
directory. The relative pathname of the
subdirectory of the
bill/school; the relative pathname of
the identically named subdirectory of the
directory would be
Linux provides two special directory names. Using a single dot
as a directory name is equivalent to specifying the working
directory. Using two dots (
..) within a pathname
refers to the directory up one level in the current path; that is, to
the parent directory. For example, if the working directory is
to the /
home directory. Similarly, if the
current working directory is
/home/bill and the
directory tree is that shown in Figure 4-1, the
../patrick/school refers to the directory
Unlike Windows 98, but like other varieties of Unix and Windows NT/2000, Linux is a multiuser operating system. Therefore, it includes mechanisms to protect data from unauthorized access. The primary protection mechanism restricts access to directories and files based on the identity of the user who requests access and on access modes assigned to each directory and file.
Each directory and file has an associated user, called the
The user who initially creates a file is the owner of the file. Each
user belongs to one or more sets of users known as
Each directory and file has an associated group, which is assigned
when the directory or file is created. The user and the group can be
Access permissions, also known as
determine what operations a user can perform on a directory or file.
Table 4-3 lists the most common permissions and
explains the meaning of each. Notice that permissions work
differently for directories than for files. For example, permission
r denotes the ability to list the contents of a
directory or read the contents of a file. A
directory or file can have multiple permissions. Only the listed
permissions are granted; any other operations are prohibited. For
example, a user who had file permission
read or write the
file but could not execute it, as indicated by
the absence of the execute permission,
Table 4-3. Common access permissions
The access modes of a directory or file consist of three sets of permissions:
Applies to the owner of the file
Applies to users who are members of the group assigned to the file
Applies to other users
The ls command, which you’ll meet in Chapter 7, lists the file access modes in the second column of its long output format, as shown in Figure 4-2. The GNOME and KDE file managers use this same format. The column contains nine characters: the first three specify the access allowed the owner of the directory or file, the second three specify the access allowed users in the same group as the directory or file, and the final three specify the access allowed to other users (see Figure 4-3).
You cannot access a hard drive partition, CD-ROM, or floppy disk until the related device or partition is mounted. Mounting a device checks the status of the device and readies it for access when it boots or when you launch a desktop environment. By default, the GNOME and KDE desktop environments automatically mount devices that use removable media.
Before you can remove media from a device, you must unmount it. You can unmount a device by using a desktop environment or issuing a command. For your convenience, the system automatically unmounts devices when it shuts down. A device can be unmounted only if it’s not in use. For example, if a user’s current working directory is a directory of the device, the device cannot be unmounted.