man.lsPlain-English help for Unix commands

history Show the commands you ran before

Lists the commands you typed earlier in your shell, each with a number. Use it to find a long command you want to run again, or to search for something you ran last week. history is built into the shell, not a separate program.

Synopsis

history [N]
history -c

Common options

Option or formWhat it does
NShow only the last N commands, for example history 20
-cClear the history of the current shell session (bash)
-d NDelete entry number N from the history (bash)
-wWrite the current session's history to the history file now (bash)
-aAppend this session's new commands to the history file (bash)
-rRead the history file into the current session (bash)

Examples

Show the last 20 commands
history 20
Search the history for a word
history | grep ssh
Run command number 482 again
!482
Run the previous command again
!!
Run the last command that started with scp
!scp

Notes

See also

Last reviewed 2026-10-07.