Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

Is there a shortcut to clear the command line when typing in it instead of keeping backspace pressed for a few long seconds?

I ask because I regularly use the Tab key to automatically fill in file names when using bash commands in the Terminal. For example instead of typing cd this_is_a_long_file_name, I will type cd th<Tab>. But then I realize I have filled in the wrong command/filename and I have to hold down backspace to clear everything and repeat the process.

share|improve this question

marked as duplicate by Eric Carvalho, chaos, karel, waltinator, nux May 27 '14 at 16:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

See this question: askubuntu.com/questions/434240/ctrll-in-terminal –  Parto May 23 '14 at 8:44
"Ctrl+c cd" is the short cut you are looking for. –  Lance Caraccioli May 23 '14 at 16:23

5 Answers 5

up vote 53 down vote accepted

Ctrl+U will only clean from the cursor to the beginning of the line, so if the cursor is at the end of the line, all the line will be cleaned, and if not, there will remain the characters after the cursor.

For a complete answer, I will say:

  • Ctrl+U - clear all the current line from the end to the beginning only if the cursor is at the end of the line.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+K - clear all the current line from the beginning to the end only if the cursor is at the beginning of the line.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+W - clear the previous word in the current line. For example if you have typed a command like git diff /path/to/some/file and you want to delete just the last parameter to the command, Ctrl+W is very useful.

    • You can then recall the cleared data using Ctrl+Y if you need.
  • Ctrl+E Ctrl+U - move the cursor to the end of the line and clear all the current line from the end to the beginning.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+A Ctrl+K - move the cursor at the beginning of the line and clear all the current line from the beginning to the end.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+C - my favourite - cancel the current command line, which implies clear all the current line no matter where the cursor is.

    • Disadvantage: you can't recall the cleared line anymore.
  • Alt+Shift+# - comment the current line, keep it in the history and bring up your prompt on a new line.

share|improve this answer
Thank you so much for the descriptive details. I have changed my choice to accept this as the answer. –  faizal May 23 '14 at 9:43
There's also Ctrl+L, which outputs a bunch of newlines to hide previous output. (I know the question is about the input line itself) –  Kroltan May 24 '14 at 14:14
+1 for Ctrl + C my favorite –  Silviu Burcea May 25 '14 at 11:02

A shortcut, Ctrl+u should do what you want.

share|improve this answer
exactly what i was looking for. thanks. –  faizal May 23 '14 at 7:25
and Ctrl+l for clearing the screen (a bit like a stty -sane, but maybe a bit less potent and far reaching). Ctrl+l works in many apps, as well (it forces a redraw in vi, for example. Usefull when someone "write" or "wall" on it) –  Olivier Dulac May 23 '14 at 8:05

If you realized you pressed the wrong key, press Ctrl+_ (underscore, you may need to hold Shift depending on your keyboard layout, e.g. Ctrl+Shift+- a US keyboard) to undo the last editing command.

If you realized that you typed the wrong command name but the argument is right, you can use cursor movement commands such as arrow keys, Home and End to navigate to the part of the command line that you want to modify.

The commands Alt+b and Alt+f move back and forth by one word at a time. Alt+d and Ctrl+w delete the next word after the cursor, or the end of the word if the cursor is within a word; Alt+b uses the shell's notion of a word while Ctrl+w uses whitespace-separated words. Esc Backspace deletes the word before the cursor.

If you want to abandon the current command line completely and start afresh, press Ctrl+c.

share|improve this answer

Use Ctrl-c to cancel the current command, this also works if you haven't yet pressed enter. It will not clear the terminal though, only bring up your prompt on a new line. To clear the visual part of the terminal, you may press Ctrl-l

share|improve this answer

Edited My answer :

Another options to clear Terminal :



tput reset


echo -e \\033c 

If you write a wrong command you can clear the terminal by this tricky way using the above commands .

wrong-command ; clear 


 wrong-command ;  tput reset 

; run both the commands, even if the first one is wrong .

share|improve this answer
The question is about a shortcut, not about another command line. How you will type another command when the current line is not empty? –  Radu Rădeanu May 23 '14 at 9:30
@RaDU you can see how man , in linux you can do anything –  nux May 24 '14 at 2:48
This answer is not relevant to the question which is about deleting the current line while typing a command. –  Guruprasad Jun 16 '14 at 11:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.