I type a really, really long command into bash. Whoops, it was the wrong command.
As of now, this means that I go through two hells:

  1. Realizing my command was useless.
  2. Having to clear my shell by holding down Backspace until the prompt is clear.

Is there a faster way?

2 Answers 2


Control + A then Control + K. The first moves your cursor to the beginning of the line, the second clears the line after the cursor.

A messier way to do this is hit enter and then hit Control + C. Credit to @billc.cn

If you want to clear the whole prompt, use Control + L.

  • 7
    Ctrl + C is quicker in some cases, although quite ugly :P
    – billc.cn
    Aug 18, 2011 at 0:43
  • 1
    I didn't think that it was relevant. I thought he wanted to clear the line, not kill a running program.
    – soandos
    Aug 18, 2011 at 0:44
  • 1
    Just type something in to bash and press Ctrl-C and see what you get.
    – billc.cn
    Aug 18, 2011 at 0:53
  • 2
    Ctrl-L clears the screen, but retains what you've typed in.
    – Alger
    Aug 18, 2011 at 3:02
  • 3
    So that does the opposite of what he wants.
    – soandos
    Aug 18, 2011 at 3:05

Ctrl-U clears the command input you've typed, up to the current cursor position. So if you're using it just after you've typed the command, but haven't moved the cursor back, it'll clear everything you've typed.

  • 2
    Actually, it "Clears the line before the cursor position. If you are at the end of the line, clears the entire line." Which is close, but not totally accurate all the time. It is the opposite of Ctrl + K
    – soandos
    Aug 18, 2011 at 3:06
  • Good point. In the situation posed in the question, though, the cursor is probably at the end of the line, so it should work for this purpose. I've fixed the answer to clarify this.
    – Alger
    Aug 18, 2011 at 3:09
  • Hence my upvote.
    – soandos
    Aug 18, 2011 at 3:09
  • @Alger for me it is always clearing everything regardless of of where the cursor is moved back or not. echo $0 returns /bin/csh.
    – Geek
    Jul 24, 2013 at 7:23
  • 1
    +1 because this works in both mysql shell and bash shell :D
    – wim
    Jan 17, 2014 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .