Quick Tip: Search shell for command-line history

While using Babun (a windows shell) sometimes I need to retype a previous command, so i just use the up/down arrow keys to navigate the commands. This is a nice feature, but what about retyping a command that you have used long time ago? no need to keep pushing the arrow keys to get it, just use this quick keyboard shortcut to search through previous commands:

  1. Open your shell and press ctrl + r
  2. Start typing a command
  3. You will have some suggestions
  4. Type again ctrl + r to narrow the suggestions

This is called reverse-i-search and it is available in terminal and bach etc.

From Stackoverflow.com:

Press Ctrl+R and type ssh. Ctrl+R will start search from most recent command to old one (reverse-search). If you have more than one command which starts with ssh, Press Ctrl+Ragain and again until you find the match.

Once you’ve found the match you can press Enter to execute the command or left / right cursor to just select the text of the command.

There is no default reverse option for Ctrl+R to invert the direction of the search but here you will find some suggestions about it.