Introduction to Unix |
|
|
|
5.8. history¶
Linux for Programmers and Users, Sections 6.4.1
-
history Bash tracks the commands that you type. You can use this to re-enter or edit a previous command. The history of past commands is normally kept in the
~/.bash_historyfile.
- SYNOPSIS
history [-c] [n]
With options, the whole history file is displayed, the size of which is capped at 1000 lines. The last n lines may also be displayed.
OPTIONS:
-c¶Clear the history
5.8.1. fc¶
-
fc Display or edit and re-execute command from the history list that matches a command searched for. See
help fcfor more details.
- SYNOPSIS
fc [-e ename] [command]
fc -s [pat=rep] [command]
Execute the previous command if no command is specified. A useful alias is
r='fc -s'. The user can typer cmdto re-execute the last command beginning with cmd and typingrre-executes the last command whiler foo=bar cmdre-executes cmd replacing foo for bar in the command.
OPTIONS:
5.8.2. Command Line Editing¶
Previous entered commands may also be recalled and edited using text editing
commands before re-executing. The default editor for the BASH shell is
emacs, but it can be changed to vi by setting set -o vi in
the ~/.bashrc file.
In both emacs and vi modes, up and down arrows on the keyboard may be used to find previous commands. Left and right arrows may also be used to move around on the command line.
In vi mode, press the ESCAPE key to enter vi’s command mode. Then j and k can move between commands and the within the command h, l, b, w, and e are used to move left, right, back word, next word, and end of word. To modify the command, use standard vi editing commands, such as cw - change word, 3cw - change 3 words, dw - delete word, x - delete character, i - insert, a - append, etc.