Navigating Bash history

Today I was doing some command line based work and I found myself scrolling too many times to reuse the long command I had written, followed by a lot of ls's and similar. I thought: this is ridiculous, there has to be a better way!

So I searched and I quickly got to history. If you enter history in a prompt, you get... a list of your last entered commands! And you don't need to scroll past irrelevant ones until you find the one you actually wanted to use. Beautiful! I was excited so I tweeted it.

Then people that knew more than me told me to use CTRL+R. I had accidentally landed in the CTRL+R weirdness before, when I wanted to reload the current page and I thought the browser window had the focus and it was the bash window instead, but since I could just ESCape, I didn't pay too much attention to it.

The way CTRL+R works is similar to a "find in page" functionality: you type some text and it will start showing results that match as you type--no need to press a 'find' button. Then to scroll across results you can press CTRL+R or CTRL+SHIFT+R (to switch between next and previous results).

Another alternative is to call history and then grep its output (grep is a filter: it will just show lines that match):

history | grep 'what you want to find'

So, for interactive searches: CTRL+R. To reconstruct what you've done (e.g. for a tutorial), history, or maybe combined with grep.

I don't quite understand how I have survived without it for so long, but it also proves that you don't need advanced command line superskills to survive in life :-P

With thanks to Jan Lehnardt and Reza Akhavan for the tips!