Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

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

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:

^C
share|improve this answer

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

Your Answer

 
discard

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.