↑↓ move Enter open Esc close

How to Search Command History in Linux

Find a command you ran before using history, reverse search and grep.

When you know you ran a command but cannot remember the exact syntax, Bash history is faster than rebuilding it from memory. Search the saved command list first, then inspect the exact command before running it again.

Step by step

1 Search history

$ history | grep "docker"

Filters the numbered history list for commands containing docker.

2 Search interactively

$ Ctrl+R

Press Ctrl+R and start typing. Press Ctrl+R again to move through older matches.

3 Show recent commands

$ history 20

Displays the last 20 commands from the current shell.

4 Run a command by number

$ !1234

Runs the history entry with that number. Inspect it first when the command can change or delete data.

Tips worth knowing

Frequently asked questions

How do I search Bash history?

Use `history | grep "text"` or press Ctrl+R for interactive reverse search.

How do I search history without running anything?

Both `history | grep` and Ctrl+R only search; they do not execute a command.

Where is Bash history saved?

Interactive Bash commonly saves it in `~/.bash_history`, subject to shell and history configuration.

The commands behind it

More how-to guides