Bash Bash history substitutions Search in the command history by pattern


Example

Press controlr and type a pattern.

For example, if you recently executed man 5 crontab, you can find it quickly by starting to type "crontab". The prompt will change like this:

(reverse-i-search)`cr': man 5 crontab

The `cr' there is the string I typed so far. This is an incremental search, so as you continue typing, the search result gets updated to match the most recent command that contained the pattern.

Press the left or right arrow keys to edit the matched command before running it, or the enter key to run the command.

By default the search finds the most recently executed command matching the pattern. To go further back in the history press controlr again. You may press it repeatedly until you find the desired command.