How do I search through the bash history?

June 12, 2011 in Recipes, Shell

Using bash type

CTRL+r first-letters-of-the-command

Note that if you type the command history all the commands that you typed will be displayed, preceded by an index. To recall a command that is indexed by the number X just type !X (no space after the exclamation mark). If you type !! the last command will be re-executed.

Sometimes you want to know when a certain command was executed. Just set the following environment variable:

export HISTTIMEFORMAT="%F %T "

Now the history contains also the time stamps associated to each command.

To learn more check the cheat sheet here, by Peteris Krumins. Check also his great blog.