Back to the command reference

history

ShellBeginner In simulator In real Linux

Show command history

Name: history

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

history is a bash builtin listing the commands you have run, numbered. History lives in memory and is written to ~/.bash_history when the shell exits; HISTSIZE and HISTFILESIZE set how much is kept.

Use !number, !! and Ctrl+R to rerun earlier commands quickly.

Syntax

history [N] | history -c

Common options

NShow only the last N entries
-cClear the history
-d OFFSETDelete entry OFFSET
-wWrite the history to ~/.bash_history now (normally on exit)
!N(bash) Re-run command number N
!!Run the last command again (as in sudo !!)
!stringRun the latest command starting with string
Ctrl+RSearch back through the history (Ctrl+R again for older ones)

Examples

  • $ history

    Show every command you ran

    Explain
  • $ history 5

    Only the last 5

    Explain
  • $ history | grep ls

    Search your history

    Explain

Related