Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
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.

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.