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.
CTRL+SHIFT+rdoesn't work for me. – Maxim Suslov Apr 05 '16 at 07:48[[ $- == *i* ]] && stty -ixonto your .bashrc and thenCTRL+swill work as the reverse ofCTRL+r– gla3dr Apr 21 '16 at 17:03STRL+sand it froze my terminal. Worth mentioning that you can unfreeze it withCTRL+qas per https://unix.stackexchange.com/a/12108/265674 – user2740 Feb 05 '19 at 13:13ctrl-Rfirst! if you typegrep ctrl-Rthen it only shows the most recent command, and repeated presses ofctrl-Rdo nothing. there's probably a really good reason for this, but i consider it a bug. – Spongman Sep 23 '21 at 16:57