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?
2 Answers
CtrlG this will abort the search
-
-
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. Commented Jan 12 at 4:29
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.
-
{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.– lornixCommented Jul 14, 2012 at 17:39 -
1for some reason Esc and Ctrl-C do not work on the Ubuntu systems I have tried (including my current 12.04). 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.– AlexiosCommented Oct 8, 2012 at 7:51