LPIC-1 Linux Professional Institute Certification Study Guide. Richard Blum
Чтение книги онлайн.

Читать онлайн книгу LPIC-1 Linux Professional Institute Certification Study Guide - Richard Blum страница 17

Название: LPIC-1 Linux Professional Institute Certification Study Guide

Автор: Richard Blum

Издательство: John Wiley & Sons Limited

Жанр: ОС и Сети

Серия:

isbn: 9781119021193

isbn:

СКАЧАТЬ shell, like many shells, provides editing features modeled after those of the Emacs editor:

      Move within the Line

      Press Ctrl+A or Ctrl+E to move the cursor to the start or end of the line, respectively. The Left and Right arrow keys move within the line a character at a time. Ctrl+B and Ctrl+F do the same, moving backward and forward within a line. Pressing Ctrl plus the Left or Right arrow key moves backward or forward a word at a time, as does pressing Esc and then B or F.

      Delete Text

      Pressing Ctrl+D or the Delete key deletes the character under the cursor. Pressing the Backspace key deletes the character to the left of the cursor. Pressing Ctrl+K deletes all text from the cursor to the end of the line. Pressing Ctrl+X and then Backspace deletes all of the text from the cursor to the beginning of the line.

      Transpose Text

      Pressing Ctrl+T transposes the character before the cursor with the character under the cursor. Pressing Esc and then T transposes the two words immediately before (or under) the cursor.

      Change Case

      Pressing Esc and then U converts text from the cursor to the end of the word to uppercase. Pressing Esc and then L converts text from the cursor to the end of the word to lowercase. Pressing Esc and then C converts the letter under the cursor (or the first letter of the next word) to uppercase, leaving the rest of the word unaffected.

      Invoke an Editor

      You can launch a full-fledged editor to edit a command by pressing Ctrl+X followed by Ctrl+E. The bash shell attempts to launch the editor defined by the $FCEDIT or $EDITOR environment variable, or it launches Emacs as a last resort.

      These editing commands are just the most useful ones supported by bash. In practice, you're likely to make heavy use of command and filename completion, the command history, and perhaps a few editing features.

      If you prefer the vi editor to Emacs, you can use a vi-like mode in bash by typing set – o vi. (vi is described in Chapter 5, “Booting Linux and Editing Files.”)

      The history command provides an interface to view and manage the history. Typing history alone displays all of the commands in the history (typically the latest 500 commands).

      To retrieve the last command in your shell history, type !! and press Enter. This will not only show you the command you recalled but execute it as well:

      You can execute a command by number via typing an exclamation mark followed by its number, as in !210 to execute command 210. Typing history – c clears the history, which can be handy if you've recently typed commands you'd rather not have discovered by others, such as commands that include passwords.

      The bash history is stored in the .bash_history file in your home directory. This is an ordinary plain-text file, so you can view it with a text editor or a command such as less (described later, in “Paging through Files with less”).

      Because your bash history is stored in a file, it can be examined by anybody who can read that file. Some commands enable you to type passwords or other sensitive data on the same line as the commands themselves, which can therefore be risky. The ∼/.bash_history file does not record what you type in response to other programs' prompts, just what you type at the bash prompt itself. Thus, if you have a choice, you should let commands that require passwords (or other sensitive data) prompt you to enter this data rather than enter such information as options to the command at the bash prompt.

      In Exercise 1.1, you'll experiment with your shell's completion and command-editing tools.

      Exercise 1.1

       Editing Commands

      To experiment with your shell's completion and command-editing tools, follow these steps:

      1. Log in as an ordinary user.

      2. Create a temporary directory by typing mkdir test. (Directory and file manipulation commands are described in more detail in Chapter 4.)

      3. Change into the test directory by typing cd test.

      4. Create a few temporary files by typing touch one two three. This command creates three empty files named one, two, and three.

      5. Type ls – l t and, without pressing the Enter key, press the Tab key. The system may beep at you or display two three. If it doesn't display two three, press the Tab key again and it should do so. This reveals that either two or three is a valid completion to your command, because these are the two files in the test directory whose filenames begin with the letter t.

      6. Type h, and again without pressing the Enter key, press the Tab key. The system should complete the command (ls – l three), at which point you can press the Enter key to execute it. (You'll see information on the file.)

      7. Press the Up arrow key. You should see the ls – l three command appear on the command line.

      8. Press Ctrl+A to move the cursor to the beginning of the line.

      9. Press the Right arrow key once, and type es (without pressing the Enter key). The command line should now read less – l three.

      10. Press the Right arrow key once, and press the Delete key three times. The command should now read less three. Press the Enter key to execute the command. (Note that you can do so even though the cursor isn't at the end of the line.) This invokes the less pager on the three file. (The less pager is described more fully later in “Paging through Files with less.”) Because this file is empty, you'll see a mostly empty screen.

      11. Press the Q key to exit from the less pager.

      Exploring Shell Configuration

      Shells, like many Linux programs, are configured through files that hold configuration options in a plain-text format. The bash configuration files are actually bash shell scripts, which are described more fully in Chapter 9. A couple of examples of these configuration files are ∼/.bashrc and /etc/profile.

      Even without knowing much about shell scripting, you can make simple changes to these files. Edit them in your favorite text editor, and change whatever needs changing. For instance, you can add directories to the $PATH environment variable, which takes a colon-delimited list of directories.

СКАЧАТЬ