Pressing arrow key up will recall the command you have used before in shell.

But what would you do if you on half way navigate through the history of your commands and you decide you want to type new command of your own?

Pressing arrow key down all the way would be too troublesome. Pressing ESC won't clear the command as in like Windows(I'm coming from Windows background).

So, how to clear the command instantly? I've googled so far but only found CTRL+C may cancel and go to new line. Is it the only way or is there a better way like ESC in Windows thats clear directly? Thanks.


You want kill-whole-line, but this is not bound by default in bash. backward-kill-line (CtrlX Backspace) and unix-line-discard (CtrlU) both erase from the current point to the beginning of the line, so just go to the end of the line and use either.

  • This works well for me.
    – Voon
    Feb 6 '12 at 16:58

For bash:

You need the keystroke sequence that is bound to the end-of-history action. By default, per §8.4.2 of the Bash User Manual, this is Meta+>, where Meta is whatever the "meta" modifier key is on your terminal or terminal emulator program. (Consult your terminal documentation and settings for the appropriate choice.)

end-of-history takes you directly all of the way to the end of the history list — i.e. back to the line that you were originally entering before you scrolled back into the history.

For the Z Shell:

You need the keystroke sequence that is bound to the end-of-buffer-or-history widget. By default, per §18.6.2 of the Z Shell Reference Manual, this is Esc> in the emacs keymap. (Note that this is specifically a prefixed Esc, not Meta, even though your terminal emulator may happen to map Meta to a prefixed Esc.)

end-of-buffer-or-history only takes you to the end of the history list if you are at the end of the buffer when you invoke it. So if you are in the middle of the buffer, you'll have to press the key sequence twice: once to get to the end of the buffer and a second time to get to the end of the history.


Aside from CTRL+C that you mentioned. I found pressing ESC and then Backspace will delete the line (some characters excluded) up until a non alphabetic character.


If you're using 'set -o vi' You can just do the following:


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.