# Linux commands: history

> 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.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-09-27 | Topics: [CLI](https://flaviocopes.com/tags/cli/) | Canonical: https://flaviocopes.com/linux-command-history/

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

You can display all the history using:

```bash
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](https://flaviocopes.com/images/linux-command-history/Screen_Shot_2020-09-04_at_08.03.10.png)

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:

```bash
history | grep docker
```

![Terminal output showing history | grep docker command results with filtered docker-related commands including git clone and docker container commands](https://flaviocopes.com/images/linux-command-history/Screen_Shot_2020-09-04_at_08.04.50.png)

To clear the history, run `history -c`

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