Skip to content

history command

Show and reuse commands you ran before.

On this page

Syntax

history [N]

Provided by the shell builtin package. Run man history for the full manual.

Common options

OptionWhat it does
NShow the last N commands
-cClear the history
-d NDelete entry N
!NRun entry N again
!!Run the last command
!stringRun the last command starting with string
Ctrl+RSearch the history interactively

Examples

  1. Show history

    history
  2. Last 20 commands

    history 20
  3. Search history

    history | grep ssh
  4. Run command number 42

    !42
  5. Repeat the last command with sudo

    sudo !!
  6. Clear history

    history -c

Tips

  • Prefix a command with a space to keep it out of history (when HISTCONTROL includes ignorespace).

← All Linux commands · Suggest a fix

Back to top