When I tell developers about Ctrl-R in BASH usually I get responses literally ranging from “Are you @#$%^&* kidding me? Who doesn’t know it?” to “Thank you. Thank you. Thank you. I owe you a beer”. Well, I made it up about the beer but I figure that people usually imply it
This BASH keybinding is so important for developer’s productivity that it’s well worth repeating it over and over again.
OK, here we go. If you know roughly the contents of the command, but can’t recall where it is in a BASH history list and don’t want to go through that list by hand, then just press Ctrl-R to do a reverse intelligent search.
As you start typing the search goes back in reverse order to the first command that matches the letters you’ve typed. By typing more successive letters you make the match more and more specific.
Once you’ve found the command you have several options:
- Run it verbatim – just press Enter
- Edit it before running – you can use arrow keys or different key bindings to navigate to the point you want to edit
- Cycle through other commands that match the letters you’ve typed – press Ctrl-R successively
- Quit the search and back to the command line empty-handed – press Ctrl-G
Added a fourth option that I forgot to mention. Thanks to commenter Taylor for reminding me about it.