history command
Show and reuse commands you ran before.
- Shell & scheduling
- Package shell builtin
- 7 options · 6 examples
On this page
Syntax
history [N]Provided by the shell builtin package. Run man history for the full manual.
Common options
| Option | What it does |
|---|---|
N | Show the last N commands |
-c | Clear the history |
-d N | Delete entry N |
!N | Run entry N again |
!! | Run the last command |
!string | Run the last command starting with string |
Ctrl+R | Search the history interactively |
Examples
Show history
historyLast 20 commands
history 20Search history
history | grep sshRun command number 42
!42Repeat the last command with sudo
sudo !!Clear history
history -c
No example matches. Check the options table or search the guides.
Tips
- Prefix a command with a space to keep it out of history (when HISTCONTROL includes ignorespace).
