27

In Ubuntu 12.04 I use CTRL-R to enter a reverse history search. If the command I want is not found (after repeated CTRL-R), how do I immediately exit back to the (empty) command prompt with no historical command entered or executed on the command line?

1
  • 1
    I can not believe that I googled this and that it has been asked and answered already :D
    – Niks
    Commented Jul 9, 2019 at 14:13

2 Answers 2

34

CtrlG this will abort the search

2
  • Reference: gnu.org/software/bash/manual/html_node/…
    – anishpatel
    Commented Nov 24, 2017 at 17:05
  • Both answers here are wrong. This will exit the search, but not "back to the (empty) command prompt with no historical command entered". Whatever search result came up will be entered on the command line, and worse, you will now be at that point in the history stack as well. At least as my bash is configured I cannot replicate any situation where no result is returned - even entering nonsense will leave me in the history stack at whatever matched the first couple letters.
    – ghostly_s
    Commented Jan 12 at 4:29
18

You can use:

  • The Emacs style keyboard quit command, Ctrl-G. Default key bindings in bash are purposefully Emacs-like.
  • The Vi style return to normal mode key bindings, Esc or Ctrl-[ (they're the same thing) .
  • Send a SIGKILL signal, Ctrl-C.

The first two have the least visible effect.

3
  • {Grin} You can prevent the display of "^C" if you add stty -ctlecho to your startup files (.bashrc,.profile,.zshrc, etc) Now ALL three methods have least visible effect.
    – lornix
    Commented Jul 14, 2012 at 17:39
  • 1
    for some reason Esc and Ctrl-C do not work on the Ubuntu systems I have tried (including my current 12.04).
    – MountainX
    Commented Jul 15, 2012 at 17:52
  • @lornix: I like to have visual feedback of Ctrl-C. Just imagine the psychological impact of pressing Ctrl-C before submitting a command like rm -rf / (extreme example), going away, then coming back to the terminal. There's practical joke potential in this, of course.
    – Alexios
    Commented Oct 8, 2012 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .