Bash History
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 emacsor
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.
C-n means control-n
M-x means escape-x (few keyboards have a `meta' key)
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 | Move to previous line in history |
| C-n | Move to next line in history |
| C-r | Reverse search (differs slightly from ksh) |
| C-a | Move to start of the current line |
| C-e | Move to end of the current line |
| C-f | Move forward (right) one character |
| C-b | Move backward (left) one character |
| M-f | Move forward one word |
| M-b | Move backward one word |
| Del | Delete the character under the cursor |
| 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-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-vx | Insert `x' literally, even if `x' is special (not ksh) |
| 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) |
| 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-) |
| TabTab | Show possible command/file name completions (ksh use M-= for file names) |
The arrow, home and end keys also work as expected.
| history [-n] | Display n lines of history (default n is 20) |
It is worth working hard today to learn the above and so be lazy tomorrow.
If you want any help using the above, or have any comments or suggestions, please contact us.
