Command History
The shell lets you display or modify previous 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 vi 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. |
The fc Command
fc stands for either
"find command" or "fix command," since it does both jobs. Use fc -l
to list history commands and fc -e
to edit them. See the fc entry
in the later section Built-in Commands for
more information.
Examples
$ history ...
Get bash Quick 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.