The Korn shell lets you display or modify previous commands. Commands in the history list can be modified using:
Line-edit mode
The fc and hist commands
Line-edit mode emulates many features of the vi and emacs editors. The history list is treated like a file. When the editor is invoked, you type editing keystrokes to move to the command line you want to execute. You can also change the line before executing it. When you're ready to issue the command, press the Return key.
Line-edit mode can be started in several ways. For example, these are equivalent:
$VISUAL=vi$EDITOR=vi$set -o viOverrides value of VISUAL or EDITOR
Note that vi starts in input mode; to type a vi command, press the Escape key first.
vi | emacs | Result |
|---|---|---|
|
| Get previous command. |
|
| Get next command. |
|
| Get previous command containing string. |
|
| Move back one character. |
|
| Move forward one character. |
|
| Move back one word. |
|
| Move forward one word. |
|
| Delete previous character. |
|
| Delete character under cursor. |
|
| Delete word forward. |
|
| Delete word backward. |
|
| Transpose two characters. |
Use fc -l to list history commands and fc -e to edit them. See the entry under "Built-in Commands" for more information.
In ksh93, the fc command has been renamed hist, and alias fc=hist is predefined.
$historyList the last 16 commands $fc -l 20 30List commands 20 through 30 $fc -l -5List the last five commands $fc -l catList the last command beginning with cat $fc -ln 5 > doitSave command 5 to file doit. $fc -e vi 5 20Edit commands 5 through 20 using vi $fc -e emacsEdit previous command using emacs $rReexecute previous command $r catReexecute last cat command $r doc=DocSubstitute, then reexecute last command $r chap=doc cReexecute last command that begins with c, but change string chap to doc