Linux Command Line and Shell Scripting Bible. Christine Bresnahan

Чтение книги онлайн.

Читать онлайн книгу Linux Command Line and Shell Scripting Bible - Christine Bresnahan страница 12

Linux Command Line and Shell Scripting Bible - Christine Bresnahan

Скачать книгу

– help to see a help screen. For more information on using help, type help help. (See a pattern here?)

      Obviously, several helpful resources are available for reference. However, many basic shell concepts still need detailed explanation. In the next section, we cover navigating through the Linux filesystem.

      Navigating the Filesystem

      When you log into the system and reach the shell command prompt, you are usually placed in your home directory. Often, you want to explore other areas in the Linux system besides just your home directory. This section describes how to do that using shell commands. To start, you need to take a tour of just what the Linux filesystem looks like so you know where you are going.

Looking at the Linux filesystem

      If you're new to the Linux system, you may be confused by how it references files and directories, especially if you're used to the way the Microsoft Windows operating system does that. Before exploring the Linux system, it helps to have an understanding of how it's laid out.

      The first difference you'll notice is that Linux does not use drive letters in pathnames. In the Windows world, the physical drives installed on the computer determine the pathname of the file. Windows assigns a letter to each physical disk drive, and each drive contains its own directory structure for accessing files stored on it.

      For example, in Windows you may be used to seeing the file paths such as:

      The Windows file path tells you exactly which physical disk partition contains the file named test.doc. For example, if you saved test.doc on a flash drive, designated by the J drive, the file path would be J:∖test.doc. This path indicates that the file is located at the root of the drive assigned the letter J.

      This is not the method used by Linux. Linux stores files within a single directory structure, called a virtual directory. The virtual directory contains file paths from all the storage devices installed on the computer, merged into a single directory structure.

      The Linux virtual directory structure contains a single base directory, called the root. Directories and files beneath the root directory are listed based on the directory path used to get to them, similar to the way Windows does it.

      Tip

      You'll notice that Linux uses a forward slash (/) instead of a backward slash (∖) to denote directories in file paths. The backslash character in Linux denotes an escape character and causes all sorts of problems when you use it in a file path. This may take some getting used to if you're coming from a Windows environment.

      In Linux, you will see file paths similar to the following:

      This indicates the file test.doc is in the directory Documents, under the directory rich, which is contained in the directory home. Notice that the path doesn't provide any information as to which physical disk the file is stored on.

      The tricky part about the Linux virtual directory is how it incorporates each storage device. The first hard drive installed in a Linux system is called the root drive. The root drive contains the virtual directory core. Everything else builds from there.

      On the root drive, Linux can use special directories as mount points. Mount points are directories in the virtual directory where you can assign additional storage devices. Linux causes files and directories to appear within these mount point directories, even though they are physically stored on a different drive.

Often system files are physically stored on the root drive. User files are typically stored on a separate drive or drives, as shown in Figure 3.2.

image

Figure 3.2 The Linux file structure

      Figure 3.2 shows two hard drives on the computer. One hard drive is associated with the root of the virtual directory (indicated by a single forward slash). Other hard drives can be mounted anywhere in the virtual directory structure. In this example, the second hard drive is mounted at the location /home, which is where the user directories are located.

The Linux filesystem structure originally evolved from the Unix file structure. In a Linux filesystem, common directory names are used for common functions. Table 3.3 lists some of the more common Linux virtual top-level directory names and their contents.

Table 3.3 Common Linux Directory Names

      The common Linux directory names are based upon the Filesystem Hierarchy Standard (FHS). Many Linux distributions maintain compliance with FHS. Therefore, you should be able to easily find files on any FHS-compliant Linux systems.

      Note

      The FHS is occasionally updated. You may find that some Linux distributions are still using an older FHS standard, while other distributions only partially implement the current standard. To keep up to date on the FHS standard, visit its official home at http://www.pathname.com/fhs/.

      When you log in to your system and reach a shell CLI prompt, your session starts in your home directory. Your home directory is a unique directory assigned to your user account. When a user account is created, the system normally assigns a unique directory for the account (see Chapter 7).

      You can move around the virtual directory using a graphical interface. However, to move around the virtual directory from a CLI prompt, you need to learn to use the cd command.

Traversing directories

      You use the change directory command (cd) to move your shell session to another directory in the Linux filesystem. The cd command syntax is pretty simplistic: cd destination.

      The cd command may take a single parameter, destination, which specifies the directory name you want to go to. If you don't specify a destination on the cd command, it takes you to your home directory.

      The destination parameter can be expressed using two different methods. One method is using an absolute directory reference. The other method uses a relative directory reference.

      The following sections describe each of these methods. The differences between these two methods are important to understand as you traverse the filesystem.

Using absolute directory references

      You can reference a directory name within the virtual directory system using an absolute directory reference. The absolute directory reference defines exactly where the directory is in the virtual directory structure, starting at the root. Think of the absolute directory reference as the full name for a directory.

      An absolute directory reference always begins with a forward slash (/), indicating the virtual directory system's root. Thus, to reference user binaries, contained within the bin directory stored within the usr directory, you would use an absolute directory reference as follows:

      With the absolute directory reference, there's no doubt as to exactly where you want to go. To move to a specific location in the filesystem using the absolute directory reference, you just specify the full pathname in the cd command:

Скачать книгу