Bash is great for interactive use, although you will probably want to use ksh for shell scripts (for portability to other Unix systems). You will have bash and ksh available under Linux.
You can configure bash to use emacs or vi editing sequences:
set -o emacs
set -o vi
If you are not running ksh or bash (eg it is not your login shell), you can invoke ksh by typing:
ksh -o emacs
The default mode is emacs and is what is explained here. Emacs mode is similar to emacs mode in ksh, a few of the differences are noted below. Only the most commonly used key sequences are listed below.
First some notation that is commonly used to describe key combinations that you will need to type.
Using the letter
x as an example:
C-xmeans control-x. Press the control (Ctrl) key, briefly press
x, release both.
M-xmeans meta-x. Briefly press the escape (Esc) key, release it, then briefly press
C-xdoes: press and hold Meta (or Alt), briefly press
x, release both.
M-C-xmeans meta control-x. Briefly press and release escape and then press
C-x, or press both Meta and Ctrl while you briefly press
C-x, then press
Some actions are also bound to keys with special markings, eg: Up Arrow, Del (or Delete). These are also shown where applicable. Note that these might not work if the terminal emulation is incorrect, ksh does not support them as well as does bash.
I have represented special keys (eg Tab) with the first letter only being capitalised, this makes is clearer when they need to be used in combination (eg TabTab).
|C-p||UpArrow||Move to previous line in history|
|C-n||DownArrow||Move to next line in history|
|C-r||Reverse search (differs slightly from ksh)|
|C-a||Home||Move to start of the current line|
|C-e||End||Move to end of the current line|
|C-f||RightArrow||Move forward (right) one character|
|C-b||LeftArrow||Move backward (left) one character|
|M-f||Move forward one word|
|M-b||Move backward one word|
|C-d||Del||Delete the character under the cursor. Also is EOF on an empty line|
|C-h||Bs||Delete the character to the left of the cursor|
|C-k||Kill the characters to the right of the cursor|
|C-u||Kill the characters to the left of the cursor (ksh clears line)|
|M-d||Delete the word to the right of the cursor|
|M-C-h||M-Bs||Delete the word to the left of the cursor|
|M-u||Convert the next word to upper case (not ksh)|
|M-l||Convert the next word to lower case (not ksh)|
|M-c||Capitalise the first character of the next word (ksh capitalised word)|
|C-t||Transpose order of the 2 characters before the cursor & move right|
|C-vx||Insert `x' literally, even if `x' is special (not ksh)|
|C-xC-e||Edit the current line using program $EDITOR (then run the line)|
|C-y||Yank (paste) the last deleted characters|
|M-y||Immediately following Yank, remove yanked text and replace with previous deleted text (not ksh)|
|M-.||Paste the last word of the previous line|
|C-o||Execute the current line, then present the next line in the history|
|M-C-e||Expand the current line as the shell would before execution (not ksh)|
|C-i||Tab||If on first word of line, complete the command name (not ksh) If not on first word of line, complete the file name (ksh use M-M-)|
|C-iC-i||TabTab||Show possible command/file name completions (ksh use M-= for file names)|
|history [-n]||Display n lines of history (default n is 20)|
|C-l||Refresh the line that is being typed (bash also clears the screen)|
|fc||Fix Command: put the last line into a file, run $EDITOR, then run the line|
It is worth working hard today to learn the above and so be lazy tomorrow.
There are more sequences than the above, but these are the most commonly used.