.. include:: ../header.txt .. _history: :command:`history` =========================== .. index:: history, fc :title:`Linux for Programmers and Users`, Sections 6.4.1 .. program:: history .. describe:: 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_history`` file. SYNOPSIS :command:`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: .. option:: -c Clear the history :command:`fc` ------------- .. program:: fc .. describe:: fc Display or edit and re-execute command from the history list that matches a command searched for. See ``help fc`` for more details. SYNOPSIS :command:`fc` [-e ename] [command] :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 type ``r cmd`` to re-execute the last command beginning with *cmd* and typing ``r`` re-executes the last command while ``r foo=bar cmd`` re-executes *cmd* replacing *foo* for *bar* in the command. OPTIONS: .. option:: -e ename Select which editor to use. Default is FCEDIT, then EDITOR, then vi. .. option:: -s [pat=rep] Replace *pat* with *rep* before executing. Command Line Editing ----------------------- .. index:: 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 :ref:`emacs`, but it can be changed to :ref:`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.