Super User is a question and answer site for computer enthusiasts and power users. 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

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?

share|improve this question
up vote 11 down vote accepted

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

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

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

share|improve this answer
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 '11 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 '11 at 3:09
Hence my upvote. – soandos Aug 18 '11 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 '13 at 7:23
+1 because this works in both mysql shell and bash shell :D – wim Jan 17 '14 at 15:22

You must log in to answer this question.

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