Last Updated: February 25, 2016
·
289
· wkjagt

Search shell history

It happens a lot that I need to reuse a command that I've already typed a little while back. What I use in those cases is reverse-i-search, which works like this:

  1. Hit CTRL+r
  2. Start typing part of the command you're looking for, not necessarily the beginning.
  3. Shell shows the last command you typed that matches the search.

Now you can do the following:

  • Use CTRL+r again to move up in the history to next matching command, or CTRL+SHIFT+r to move down.
  • any other key quits search and leaves you at the found point in your history, using the normal behaviour of that key. So ENTER executes the found command, etc.