Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 7 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 @billc.cn

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

share|improve this answer
6  
Ctrl + C is quicker in some cases, although quite ugly :P –  billc.cn Aug 18 '11 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 '11 at 0:44
1  
Just type something in to bash and press Ctrl-C and see what you get. –  billc.cn Aug 18 '11 at 0:53
1  
Ctrl-L clears the screen, but retains what you've typed in. –  Alger Aug 18 '11 at 3:02
1  
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 at 15:22

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.