Linux Shell Editing Shortcuts
Tips and Tricks of Power Shell Users
If you want to learn to use the Linux command line, you're going to have to do a lot of typing, and make sure you type everything accurately ... right?
No! One of the secrets power shell users know is that they don't really have to be great typists. They take advantage of the typing shortcuts the shell offers.
You probably know you can erase the last character by hitting the backspace key. But you can correct mistakes in a lot more ways than that.
First trick: Ctrl-U deletes everything back to the beginning of the line. No need to hold the backspace key down and wait while it repeats; a single Ctrl-U is much faster. It's great for when you change your mind about a command or want to clear the line and think about what to do next. Think of U as Undoing the line you were typing.
Next -- and my personal favorite -- is Ctrl-W to erase the last word. Like Ctrl-U, it's a lot faster than holding the backspace key down and waiting. But unlike Ctrl-U, it lets you keep some of what you already typed. Try it -- you'll be amazed how handy it is.
You may have noticed that you can use the left and right arrow keys while you're typing a line in the shell. But Home and End don't work to go to the beginning and end of a line -- how do you do that? The secret: type Ctrl-A to go to the beginning of the line, Ctrl-E to go to the end. To remember those two, think of A as being at the beginning of the alphabet while E just stands for "End".
If you move the cursor back while you're editing a line, with the left arrow or Ctrl-A, you might also be interested in Ctrl-K. It deletes from the cursor position to the end of the line.
Enabling editing shortcuts in other apps
Most of these editing shortcuts will work in lots of other Linux apps besides the shell, though not every program supports all of them. Try them in editors, mail programs, browsers.
In some programs and on some Linux distros, they aren't enabled by default. If you find them useful, you can turn them on for Firefox and any GTK-based applications by setting your Gnome key theme to "Emacs". To do that, either add the line
gtk-key-theme-name = "Emacs"to a file named .gtkrc-2.0 in your home directory, or run this command:
gconftool-2 --set /desktop/gnome/interface/gtk_key_theme Emacs --type string