Search forward in command line history

5,705

Solution 1

Bash also has a forward history search, which is mapped to CtrlS.

Often, this shortcut will be masked by the stop flow control key binding for the terminal (check with stty -a). This will make your terminal stop outputting anything—not quite what you want.

To get forward history search working, you have two options:

  1. Disable the flow control altogether: stty -ixon

  2. Bind flow control to something else, e.g. to CtrlX with stty stop ^X

Solution 2

Ctrl + S should search the history "forward". Or whatever bind -p tells you is bound to forward-search-history.

Share:
5,705

Related videos on Youtube

j1b3
Author by

j1b3

CTO in a Mobile Marketing Company (Web Ads, SMS, App dev ...)

Updated on September 18, 2022

Comments

  • j1b3
    j1b3 over 1 year

    With Ctrl + R you can search in previous commands. If you hit Ctrl + R again, it will displays older previous commands. The problem it that this search is "one way", it always displays older results each time you press Ctrl + R.

    Right now, if I hit Ctrl+R too many times and miss the result I was actually looking for, I have to stop my search (Ctrl + G) and restart it from the beginning.

    Is there any command (Ctrl + something ) to search for "newer" results than the one currently displayed?