Command History
The shell lets you display or modify previous commands. Using the history command, you can manage the list of commands kept in the shell’s history; see history for more information. This section focuses on the facilities for editing stored commands. Commands in the history list can be modified using:
Line-edit mode
The fc command
C-shell–style history
Line-Edit Mode
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 Enter key.
Emacs editing mode is the default. To control
command-line editing, you must use either set
-o vi
or set -o emacs
; Bash
does not use variables to specify the editor.
Note that the vi editing mode starts in input mode; to type a vi command, press the Escape key first.
Common editing keystrokes
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. |
Both editing modes allow you to use ...
Get bash Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.