Skip to content
FLAVIO COPES
flaviocopes.com
2026

Linux commands: history

By Flavio Copes

Learn how the Linux history command shows your past commands, how to rerun one with the !number syntax, search them with grep, and clear with history -c.

~~~

Every time we run a command, that’s memorized in the history.

You can display all the history using:

history

This shows the history with numbers:

Terminal output showing history command displaying numbered command lines 113-127 with various commands like passwd, ls, wc, and open

You can use the syntax !<command number> to repeat a command stored in the history, in the above example typing !121 will repeat the ls -al | wc -l command.

Typically the last 500 commands are stored in the history.

You can combine this with grep to find a command you ran:

history | grep docker

Terminal output showing history | grep docker command results with filtered docker-related commands including git clone and docker container commands

To clear the history, run history -c

The history command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

Tagged: CLI · All topics
~~~

Related posts about cli: