Linux Bible. Christopher Negus

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

Читать онлайн книгу Linux Bible - Christopher Negus страница 40

Linux Bible - Christopher Negus

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

that you don't have to delete the entire line and start over. Likewise, you can recall a previous command line and change the elements to make a new command.

      By default, the bash shell uses command-line editing that is based on the emacs text editor. (Type man emacs to read about it, if you care to do so.) If you are familiar with emacs, you probably already know most of the keystrokes described here.

      TIP

      If you prefer the vi command for editing shell command lines, you can easily make that happen. Add the following line to the .bashrc file in your home directory:

        set -o vi

      The next time you open a shell, you can use vi commands to edit your command lines.

      To do the editing, you can use a combination of control keys, meta keys, and arrow keys. For example, Ctrl+F means to hold down the Ctrl key, and type f. Alt+F means to hold down the Alt key, and type f. (Instead of the Alt key, your keyboard may use a Meta key or the Esc key. On a Windows keyboard, you can use the Windows key.)

      To try out a bit of command-line editing, enter the following:

       $ ls /usr/bin | sort -f | less

      This command lists the contents of the /usr/bin directory, sorts the contents in alphabetical order (regardless of case), and pipes the output to less. The less command displays the first page of output, after which you can go through the rest of the output a line (press Enter) or a page (press spacebar) at a time. Simply press q when you are finished. Now, suppose that you want to change /usr/bin to /bin. You can use the following steps to change the command:

      1 Press the up arrow (↑) key. This displays the most recent command from your shell history.

      2 Press Ctrl+A. This moves the cursor to the beginning of the command line.

      3 Press Ctrl+F or the right arrow (→) key. Repeat this command a few times to position the cursor under the first slash (/).

      4 Press Ctrl+D. Type this command four times to delete /usr from the line.

      5 Press Enter. This executes the command line.

Keystroke Full Name Meaning
Ctrl+F Character forward Go forward one character.
Ctrl+B Character backward Go backward one character.
Alt+F Word forward Go forward one word.
Alt+B Word backward Go backward one word.
Ctrl+A Beginning of line Go to the beginning of the current line.
Ctrl+E End of line Go to the end of the line.
Ctrl+L Clear screen Clear screen and leave line at the top of the screen.
Keystroke Full Name Meaning
Ctrl+D Delete current Delete the current character.
Backspace Delete previous Delete the previous character.
Ctrl+T Transpose character Switch positions of current and previous characters.
Alt+T Transpose words Switch positions of current and previous words.
Alt+U Uppercase word Change the current word to uppercase.
Alt+L Lowercase word Change the current word to lowercase.
Alt+C Capitalize word Change the current word to an initial capital.
Ctrl+V Insert special character Add a special character. For example, to add a Tab character, press Ctrl+V+Tab.
Keystroke Full Name Meaning
Ctrl+K Cut end of line Cut text to the end of the line.
Ctrl+U Cut beginning of line Cut text to the beginning of the line.
Ctrl+W Cut previous word Cut the word located behind the cursor.
Alt+D Cut next word Cut the

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