Parliament Hill Computers Ltd
Parliament Hill Computers Ltd
 
Home

About PHCL

Recent Projects

Clients

Links

Accessibility

Technical Tutorials

Downloads

Contact PHCL



Best viewed with the FireFox web Browser Get Firefox!

Valid HTML 4.01!

Valid CSS!

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 emacs
or
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).

Finding a line in history
C-pMove to previous line in history
C-nMove to next line in history
C-rReverse search (differs slightly from ksh)

Moving in the current line
C-aMove to start of the current line
C-eMove to end of the current line
C-fMove forward (right) one character
C-bMove backward (left) one character
M-fMove forward one word
M-bMove backward one word

Editing the current line
DelDelete the character under the cursor
BsDelete the character to the left of the cursor
C-kKill the characters to the right of the cursor
C-uKill the characters to the left of the cursor (ksh clears line)
M-dDelete the word to the right of the cursor
M-BsDelete the word to the left of the cursor
M-uConvert the next word to upper case (not ksh)
M-lConvert the next word to lower case (not ksh)
M-cCapitalise the first character of the next word (ksh capitalised word)
C-vxInsert `x' literally, even if `x' is special (not ksh)

Kill ring and previous line
C-yYank (paste) the last deleted characters
M-yImmediately following Yank, remove yanked text and replace with previous deleted text (not ksh)
M-.Paste the last word of the previous line
C-oExecute the current line, then present the next line in the history

Expansion
M-C-eExpand the current line as the shell would before execution (not ksh)
TabIf 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-)
TabTabShow possible command/file name completions (ksh use M-= for file names)

The arrow, home and end keys also work as expected.

You may also find useful
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.

Return to tutorial home.

If you want any help using the above, or have any comments or suggestions, please contact us.