62

How can I clear the current line in the command prompt? (I'm using Windows 7.)

Too often, I enter a command, execute it, get many lines of output, then wish to enter another command. But before entering the second command, I press the up arrow key to review the first command, then I find I have to hold backspace for 30-or so characters. (I can't just press down again to get an empty line. Nor can I get it by pressing up again.)

  • @myrddim has it but that aside, some poor alternatives are keep tapping up until you have something short then hold backspace. another one is make the command be a bad command or filename, or rather, an "'sdfd' is not recognised as an internal or external command" so move the cursor a bit with left arrow and just tap a letter or don't and just tap a letter at the end, mess up the cmd input, then hit ENTER, get that error and the next line will be blank. – barlop Mar 5 '12 at 18:55
  • @barlop That is indeed a poor workaround! It only takes one keystroke. If you can't use the Esc key, you could use AutoHotkey to simulate it. – iglvzx Mar 5 '12 at 19:20
99

The Escape (Esc) key will clear the input line.

In addition, pressing Ctrl+C will move the cursor to a new, blank line. This may be helpful as the input you just reviewed remains visible while you type the new command.

  • 3
    And if you want to clear the whole screen, you can use the cls command. :) – iglvzx Mar 5 '12 at 18:52
  • 7
    As a side note, on UNIX it's ctrl+u. – 0sh Oct 22 '12 at 23:12
  • 2
    Which would be relevant if the question wasn't specifically targeted at the Windows 7 command prompt. :-) Also, I believe this is shell specific, as I am reasonably certain some shells have the same behavior as Windows when pressing Ctrl+C. – Myrddin Emrys Oct 22 '12 at 23:19
  • 2
    @MyrddinEmrys on Windows it is cls – CJ7 Jun 1 '16 at 5:24
  • 2
    Note: the CTRL+C command will also exit any command line session you are having, i.e python, and return you back to the command line environment. – SexyBeast Jul 14 '16 at 7:41
15

Myyrddin covered Esc and CtrlC which clear the current command input and initiate a new line respectively.

However, there are also two more shortcuts related to clearing the current input in CMD: CtrlHome and CtrlEnd.

CtrlHome allows you to clear all characters in the command input to the left of the cursor.

CtrlEnd does the same for all characters to the right of the cursor.

Both are fairly useful and, once internalised and gotten used to, could speed up editing in CMD by quite a bit.

  • 2
    I didn't know about these keystrokes; thank you. May you get the upvotes you deserve. – Myrddin Emrys Jan 31 '17 at 13:47
  • 1
    Same here. Being used to Bash I always wanted those. OP is my savior. – uranusjr Jul 25 '17 at 15:57
  • Out of curiosity, what are the equivalents in Bash? – Hashim Jul 25 '17 at 22:27
  • 1
    From bash(1): (Ctrl)+(X), (Rubout) is defined to be backward-kill-line; i.e., kill backward to the beginning of the line; i.e., the same as (Ctrl)+(Home) in Windows CMD. “Rubout” may be Backspace or Delete, so try (Ctrl)+(X), (Backspace) and (Ctrl)+(X), (Delete). Also, (Ctrl)+(U) is unix-line-discard; i.e., kill backward from the insertion point (cursor) to the beginning of the line; i.e., also the same as (Ctrl)+(Home).  (Ctrl)+(K) is defined to be kill-line; i.e., kill the text from the insertion point to the end of the line; i.e., the same as (Ctrl)+(End) in Windows CMD. – Scott Aug 26 '18 at 5:47
  • 1
    Just to be clear: (Ctrl)+(U) is a long-standing, general feature of Unix.  It works in old, non-Linux, non-GNU, non-bash systems; it works in vi; it works if you do cat > file123.  The others are specific to the bash command line. – Scott Jul 22 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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