You can also set up the up and down arrows to do a slightly different search by adding these lines to ~/.inputrc:
"\e[A": history-search-backward
"\e[B": history-search-forward
Instead of searching for a substring anywhere in the command (like Ctrl-r) it will search for a command starting with the text to the left of the cursor. For example, if I run these commands:
$ ls bart
$ ls fools
then type ls
and press Up twice, it will show ls bart
and the cursor in the same place. Compare with Ctrl-r, where it would find the ls
twice in the last line, so you'd have to press it once again to find the previous line.
These approaches both have their strengths, and both of them can save a lot of time.