I search the terminal command history by pressing Ctrlr but what if:

This is an old command

This is an | less -S older command

I press Ctrlr and then I type "this is an" and the old command commes up but not the older. How can I search all the "this is an" commands? Is it possible to pipe all similar commands to grep or something?

If I set -o vi, how do I undo it?

  • 3
    to undo vi-style line editing just set -o emacs since there only exists emacs and vi line editing mode. Sep 11, 2012 at 12:34
  • In addition to other answers you can also search for a condition and view only 10 results history | grep <SEARCH_STRING> | head head command will give you last 10 results.
    – Mārcis P
    Feb 26, 2021 at 10:24

2 Answers 2


To search for a command in the history press ctrl+r multiple times ;-)

You can also grep through the history using:

 history | grep YOUR_STRING

If I understand correctly and you want to search for older entries, just press ctrl+r again.

  • 2
    How can i toggle through them after I enter a search criteria?
    – powder366
    Jan 13, 2018 at 13:37
  • @powder366 just press CTRL+R again and again, it will jump backwards trough history
    – Sliq
    Nov 4, 2021 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.