I usually end up using CTRL+r for (reverse-i-search), however, sometimes I pass the command that I was looking for; if I do again a (reverse-i-search) it doesn't find it anymore. I assume that the current pointer to the command history is before the command I'm looking for.

Does anybody knows how to go back to the most current command in the history without having to click 1000 times the down arrow?

  • 1
    The reverse search is a feature of bash (and the readline libaries), so I've edited the title and question a little to reflect that. – Doug Harris Jul 1 '10 at 19:56
  • if you go past the command you wanted, do CTRL+SHIFT+R to go back – Ricky Robinson Mar 7 '14 at 17:18

There's a similar question on stackoverflow.com.

The best answer there is to use Ctrl+G to cancel the current search.

  • This really is not the best answer. The best answer is the one given by Dennis Williamson: add stty -ixon in your .bashrc (or in some other corresponding config file), and then Ctrl-S steps forward in history, similarly as Ctrl-G steps backward. First Ctrl-S keypress after Ctrl-G changes reverse-i-search to i-search, the next Ctrl-S takes the first step forward. Then each Ctrl-S takes one step forward more. – nrz Jun 8 '14 at 9:54
  • or if you already terminated the search (e.g. by hitting esc or an arrow-key), you can hit Esc followed by '>' – Superole Feb 24 '15 at 16:47

Actually, another answer to that question gives a better option.

In your ~/.bashrc add the following line:

stty -ixon

Then you can use Ctrl-s to step forward through the history in the same way as you would use Ctrl-r to step backward.

This will even work to start a new forward search (called i-search as opposed to reverse-i-search) while browsing through history. Suppose you do Ctrl-r and type some text of a command near your destination then press up arrow several times overshooting what you were really looking for (or you change your mind). Now press Ctrl-s and type a few characters from that line. Zoooom! Straight to it.

  • 2
    what's the implication of stty -ixon? does it disable something that might be needed in other situations? – Gregory Pakosz Feb 1 '12 at 19:39
  • 5
    @GregoryPakosz: It disables XON/XOFF (software flow control), which is useless from the keyboard now that we're communicating at a little bit higher rate than 300 baud. – Dennis Williamson Feb 1 '12 at 22:31
  • thank you, googled for a while and came to the same conclusion, it's mostly useless nowadays – Gregory Pakosz Feb 3 '12 at 11:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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