Affordable web hosting - 270 CHAPTER 17 COOL SHELL TRICKS Table
270 CHAPTER 17 COOL SHELL TRICKS Table 17-1. Keyboard Shortcuts in BASH (Continued) Shortcut Description Editing Ctrl+U Delete everything behind cursor to start of line Ctrl+K Delete from cursor to end of line Ctrl+W Delete from cursor to beginning of word Alt+D Delete from cursor to end of word Ctrl+T Transpose characters on left and right of cursor Alt+T Transpose words on left and right of cursor Miscellaneous Ctrl+L Clear screen (everything above current line) Ctrl+U Undo everything since last command1 Alt+R Undo changes made to the line2 Ctrl+Y Undo deletion of word or line caused by using Ctrl+K, Ctrl+W, and so on3 Alt+L Lowercase current word (from the cursor to end of word) 1 In most cases, this has the effect of clearing the line. 2 This is different from Ctrl+U, because it will leave intact any command already on the line, such as one pulled from your command history. 3 This allows primitive cutting and pasting. Delete the text and then immediately undo, after which the text will remain in the buffer and can be pasted with Ctrl+Y. Shortcuts for System Control In terms of the control over your system offered by keyboard commands, as mentioned in Chapter 16, pressing Ctrl+Z has the effect of stopping the current program. It suspends the program until you switch back into it or tell it to resume in another way, or manually kill it. In the same style, pressing Ctrl+C while a program is running will quit it. This sends the program s process a termination signal, a little like killing it using the top program. Ctrl+C can prove handy if you start a program running by accident and quickly want to end it, or if a command takes longer than you expected to work and you cannot wait for it to complete. It s also a handy way of attempting to end crashed programs. Some complicated programs don t take too kindly to being quit in this way, particularly those that need to save data before they terminate. However, most should be okay. Ctrl+D is another handy keyboard shortcut. This sends the program an end-of-file (EOF) message. In effect, this tells the program that you ve finished your input. This can have a variety of effects, depending on the program you re running. For example, pressing Ctrl+D on its own at the shell prompt when no program is running will cause you to log out (if you re using a GUI terminal emulator like GNOME Terminal, the program will quit). This happens because pressing Ctrl+D informs the BASH shell program that you ve finished your input. BASH then interprets this as the cue that it should log you out. After all, what else can it do if told there will be no more input?