Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Windows command line (powershell and cmd), when you press Esc key while on a line, whatever you have typed at the prompt is removed.

I found that pressing Esc key at bash prompt does nothing. Pressing Esc and then backspace deletes a word, but this has to be done for each word.

I am learning Bash incrementally and sometimes type something stupid in the middle of the line and feel that it is better to type from scratch again. To do this, pressing backspace is the only way I found until now.

What do you do?

I am aware of the clear command and Ctrl-L shortcut, but I am not talking about clearing the entire terminal. Just the line.

share|improve this question
A while back I posted a list of useful readline keyboard shortcuts on superuser. You may find them useful as well. (Readline is the library that bash uses for line-editing.) –  jw013 Feb 7 '12 at 1:10
hey jw013, thank you for a nice edit. :-) –  Nanda Feb 9 '12 at 0:57

3 Answers 3

up vote 11 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
You are correct, it is not bound to anything. I just found out that using bind -P. I guess Ctrl-U and then Ctrl-Y is the only option then. –  Nanda Feb 6 '12 at 6:34
You'll find that a number of the default bindings are derived from the key sequences in the Emacs editor and that those bindings show up elsewhere, too. –  Blrfl Feb 6 '12 at 11:41
@Blrfl to extend your comment, most of these keybindings have been abstracted into the readline library, which a large number commandline programs use and which is why they all have similar line editing keys. –  jw013 Feb 7 '12 at 1:07

You could use Ctrl+C to abandon whatever you were typing and get an empty new command line, see Is CTRL+C incorrect to use to return to command line?.

share|improve this answer

Ctrl+a goes to the beginning of the line and Ctrl+k deletes to the end of the line

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.