Linux Command Line and Shell Scripting Bible. Christine Bresnahan
Чтение книги онлайн.

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

СКАЧАТЬ style="font-size:15px;">      Note

      Though the focus is on the GNU bash shell, additional shells are reviewed in this book. Chapter 23 covers working with alternative shells, such as dash and tcsh.

      In the earlier /etc/passwd sample entry, the user christine has /bin/bash set as her default shell program. This means when christine logs into the Linux system, the bash shell program is automatically started.

      Although the bash shell program is automatically started at login, whether a shell command line interface (CLI) is presented depends on which login method is used. If a virtual console terminal is used to log in, the CLI prompt is automatically presented, and you can begin to type shell commands. However, if you log into the Linux system via a graphical desktop environment, you need to start a graphical terminal emulator to access the shell CLI prompt.

      Using the Shell Prompt

      After you start a terminal emulation package or log in to a Linux virtual console, you get access to the shell CLI prompt. The prompt is your gateway to the shell. This is the place where you enter shell commands.

      The default prompt symbol for the bash shell is the dollar sign ($). This symbol indicates that the shell is waiting for you to enter text. Different Linux distributions use different formats for the prompt. On this Ubuntu Linux system, the shell prompt looks like this:

      On the CentOS Linux system, it looks like this:

      Besides acting as your access point to the shell, the prompt can provide additional helpful information. In the two preceding examples, the current user ID name, christine, is shown in the prompt. Also, the name of the system is shown, server01. You learn later in this chapter about additional items shown in the prompt.

      Tip

      If you are new to the CLI, keep in mind that, after you type in a shell command at the prompt, you need to press the Enter key for the shell to act upon your command.

      The shell prompt is not static. It can be changed to suit your needs. Chapter 6, “Using Linux Environment Variables,” covers modifying your shell CLI prompt configuration.

      Think of the shell CLI prompt as a helpmate, assisting you with your Linux system, giving you helpful insights, and letting you know when the shell is ready for new commands. Another helpful item in the shell is the bash Manual.

      Interacting with the bash Manual

      Most Linux distributions include an online manual for looking up information on shell commands, as well as lots of other GNU utilities included in the distribution. You should become familiar with the manual, because it's invaluable for working with commands, especially when you're trying to figure out various command line parameters.

The man command provides access to the manual pages stored on the Linux system. Entering the man command followed by a specific command name provides that utility's manual entry. Figure 3.1 shows an example of looking up the xterm command's manual pages. This page was reached by typing the command man xterm.

image

Figure 3.1 Manual pages for the xterm command

      Notice the xterm command DESCRIPTION paragraphs in Figure 3.1. They are rather sparse and full of technical jargon. The bash manual is not a step-by-step guide, but instead a quick reference.

      Tip

      If you are new to the bash shell, you may find that the man pages are not very helpful at first. However, get into the habit of using them, especially to read the first paragraph or two of a command's DESCRIPTION section. Eventually, you will learn the technical lingo, and the man pages will become more helpful to you.

      When you use the man command to view a command's manual pages, they are displayed with something called a pager. A pager is a utility that allows you to page through displayed text. Thus, you can page through the man pages by pressing the spacebar, or you can go line by line using the Enter key. In addition, you can use the arrow keys to scroll forward and backward through the man page text (assuming that your terminal emulation package supports the arrow key functions).

      When you are finished with the man pages, press the q key to quit. When you quit the man pages, you receive a shell CLI prompt, indicating the shell is waiting for your next command.

      Tip

      The bash manual even has reference information on itself. Type man man to see manual pages concerning the man pages

The manual page divides information about a command into separate sections. Each section has a conventional naming standard as shown in Table 3.1.

Table 3.1 The Linux man Page Conventional Section Names

      Not every command's man page has all the section names described in Table 3.1. Also, some commands have section names that are not listed in the conventional standard.

      Tip

      What if you can't remember the command name? You can search the man pages using keywords. The syntax is man – k keyword. For example, to find commands dealing with the terminals, you type man – k terminal.

In addition to the conventionally named sections for a man page, there are man page section areas. Each section area has an assigned number, starting at 1 and going to 9; they are listed in Table 3.2.

Table 3.2 The Linux man Page Section Areas

      Typically, the man utility provides the lowest numbered content area for the command. For example, looking back to Figure 3.1 where the command man xterm was entered, notice that in the upper-left and upper-right display corners, the word XTERM is followed by a number in parentheses, (1). This means the man pages displayed are coming from content area 1 (executable programs or shell commands).

      Occasionally, a command has man pages in multiple section content areas. For example, there is a command called hostname. The man pages contain information on the command as well as an overview section on system hostnames. To see the pages desired, you type man section# topic. For the command's man pages in section 1, type man 1 hostname. For the overview man pages in section 7, type man 7 hostname.

      You can also step through an introduction to the various section content areas by typing man 1 intro to read about section 1, man 2 intro to read about section 2, man 3 intro to read about section 3, and so on.

      The man pages are not the only reference. There are also the information pages called info pages. You can learn about the info pages by typing info info.

      In addition, most commands accept the – help or – help option. For example, you can type hostname СКАЧАТЬ