8

In Bash, when I hit Ctrlr, I can search the command history backward. If I would like to search forward again, what shall I do?(The Ctrls doesn't work.)

My Bash is: GNU bash, version 4.2.25(1)-release (i686-pc-linux-gnu)

9
  • Ctrl-S should work. At least it works on my machine in an xterm. If this doesn't work, type stty -ixon.
    – vinc17
    Jul 8 '14 at 22:24
  • Does your shell lock-up with ctrl-s, and recover with ctrl-q? If so you need to disable flow control. (tell us if it does, so we can give the correct help) Jul 8 '14 at 22:26
  • 2
    With flow control, Ctrl-S stops the flow, while Ctrl-Q re-enables it; that's why it solves your problem. Flow control is useless nowadays. I suggest that you disable it with stty -ixon (put that in your shell startup file for interactive shells).
    – vinc17
    Jul 8 '14 at 22:44
  • 3
    2) you can only go forward, after going backward: you can not do forward to what you will type later, the computer is not clever enough to figure this out. Jul 8 '14 at 22:45
  • 1
    Flow control was used to pause the output, useful if the computer outputting to fast, but not so fast that you can not see roughly where it is. These days it is useless, as the computer is way to fast to make it useful. (a bit of software could be fast enough to react, so it could be used there. Other flow control protocols are used in TCP for example) But the short story is that if you disable it, you will not miss it. Jul 8 '14 at 23:04
10

Your tty probably has the ixon and ixany bits set.

ixon enables XON/XOFF flow-control, so when you hit CtrlS, the tty device stops output. But ixany means that any other key will restart output, so most people don't notice it ever stopped.

Some people find flow-control useful, but you can disable it by running:

stty -ixon

and then CtrlS should work as expected for searching in bash.

You might want to add that to your ~/.bashrc!

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.