13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ USING THE COMMAND LINE BETTER• Alt-. (period) or Esc-. (period): Both of these insert the final argument to the mostrecent command at the cursor point. This is very useful when moving files aroundand editing them; you can repeatedly apply different operations to the same file.It’s also useful for other sorts of file processing. Alt-. falls more readily under thefingers, but Esc and then . is a handy alternative to know if you’re using an oddkeyboard (Alt-. won’t work properly on some keyboards) and in particular if you’reusing a Mac.> cp /usr/share/doc/README /usr/share/doc/README.local> vim Alt-.vim /usr/share/doc/README.local■ Note In general, if you have trouble with Alt, try replacing it with Esc. You don’t have to hit the second key atthe same time as Esc but can hit it immediately afterward if you prefer. In other words, pressing Esc and then .(period) works exactly the same as Esc-. (period).• Alt-Ctrl-Y: This inserts the first argument to the previous command at the cursorpoint. If you want the nth argument, hit Alt-n beforehand. So, pressing Alt-2 Alt-Ctrl-Y will give you the second argument to the previous command. (You may findyou need to replace Alt with Esc on some keyboards, so you’d press Esc-2 Esc-Ctrl-Y in this example.) It’s a lot of keys to remember, but it’s useful once in a while,especially if your arguments are particularly long and you’re doing somethingcomplicated. Also bear in mind that Alt-0 or Esc-0 will give you the first word ofthe last command, which will probably be the command name and can be usefulif repeating a command.> cp /etc/defaults/ldap /etc/defaults/ldap.bk> vim Alt-C-Yvim /etc/defaults/ldap• Alt-?: This provides history expansion on the current line. (That is, hit this onceinstead of Tab twice to get a list of possible expansions. This saves a singlekeystroke but uses more fingers!)• Ctrl-T and Alt-T: These transpose characters and words, respectively. This will pullthe character/word behind the cursor over the character/word at the cursor.(Unfortunately, in at least some terminals—for example, gnome-terminal—Alt-Tis overridden, so this may not work for you. However, Esc-T should still work.)> cd /urs Ctrl-T> cd /usr• Ctrl-W and Alt-Backspace: Both of these delete the word behind the cursor, butCtrl-W uses whitespace as a boundary, whereas Alt-BS uses nonalphanumericcharacters. So, if you have file.txt and hit Ctrl-W, you’ll delete the lot; Alt-BS willleave you with file., which has very obvious uses. (It also works withunderscores.)173Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!