Recursively search Bash command history

I love the history recall features in Bash. I recently was searching for a short perl script I wrote a couple days ago but !:p was only giving me the first hit in the command history (IE the most recently used match) so a quick google search resulted in me stumbling across this beautiful history feature.

Pressing ctrl+r will allow you to recursively search through matching commands in your terminal history



If you pass the command you want to run, pressing ctrl+s will move you forward in the same manner.


Ctrl+s didn’t work for me at first (and realize you have to hit it twice to go forward one – first time switches you into the forward-search mode with the currently displayed result shown), if you find yourself in the same situation add this to your ~/.bash_profile or ~/.bashrc (whichever is sourced when a new term is started)

stty -ixon