Command Prompt is a fantastic tool that helps you manage your Windows system, especially to diagnose and troubleshoot errors and operate your system more effectively.
However, if you need to enter many commands on this interface, the previous commands and their results may seem distracting. This can even prevent you from focusing on a certain command on the process due to the clutter.
The best practice while performing such operations is to regularly clear the prompt to remove any unnecessary data or history.
How to Clear Screen on Command Prompt?
By default, Command Prompt only contains one quick way to clear the screen. However, you can also create additional methods to do so and make the process even quicker.
Using CLS Command
The method most people are familiar with would be the CLS command. This command is short for CLear Screen and has been around since MS-DOS.
- You can simply type
cls
on the prompt whenever you want to clear the screen and press Enter to run it. This command doesn’t have any other flags. - You can also check Microsoft’s definition of the command using the help command (/?), i.e.,
cls /?
Using Doskey Macro
Using the CLS command is very easy. However, there are even easier ways of clearing the screen on Command Prompt. The command line includes a doskey
command, which you can use to create a macro.
A macro is a replacement for a full command or multiple commands. If you make a macro on the Command Prompt’s session, it will be valid for the full session.
Here’s how you can create and use the macro to clear the screen on CMD:
- Open Command Prompt if you haven’t already done so.
- Enter the following command:
doskey c=cd\ $T cls
- You can replace c with anything. However, it’s better to make it a one-letter macro to make clearing CMD quicker than using
cls
.
After that, you can type and enter “c
”, or the macro you set, after running any number of commands to clear the screen.
Creating CMD File and Including It on Path
Using the Doskey command can only create a substitute for the CLS command for one active Command Prompt session. However, you can create a permanent replacement by creating a .cmd
file and including the file in a system path location.
Here are the necessary steps for this process:
- Open Run by pressing Win + R.
- Type
notepad
and press Enter to open this text editor. - Type
@cls
on the notepad. - Press Ctrl + Shift + S to save it with another extension.
- Before saving, set Save as type to All files and the File name to
c.cmd
. You can replacec
on the name with your preferred substitute shortcut forcls
. - You can save it to
C:\Windows\system32
or any location already included in your system path (see below). - Or you can save it to a new location. Then, you need to include the folder in the path variables. To do so,
- Navigate to the location where you saved
c.cmd
- Copy the path of the location from the address bar.
- Open Run and enter
systempropertiesadvanced
to open the Advanced tab of System Properties. - Go to Environment Variables.
- Double-click on Path under System variables.
- Select New and paste the path you copied earlier.
- Click OK thrice to save the changes and exit System Properties.
- Navigate to the location where you saved
Now, you can enter c
or the substitute letter of your choice on Prompt and clear the screen anytime you want.
Using PowerShell’s Clear-Host Command
Windows PowerShell uses the Clear-Host cmdlet as an alternative to Command Prompt’s CLS command. So, you can also enter powershell clear-host
in place of cls
to clear the screen.
This command opens PowerShell CLI in the prompt, runs the Clear-Host cmdlet, and then exits back to Command Prompt, making it slightly slower than CLS. While there’s no real reason to use this command instead, we have included it in this article for your knowledge.
Using AutoHotkey Shortcut
You can also use a shortcut application to create a hotkey to clear the screen. In this way, you can use a hotkey directly to clear the screen without having to type a command and press Enter.
We have provided the steps to create a shortcut using the open-source app, AutoHotkey in this article. If you want to use any other programs, you need to check the official sources for the exact steps.
- Download and install AutoHotkey.
- After the installation, right-click on your desktop or any location in the file explorer.
- Select New > AutoHotkey Script.
- Name it as you wish.
- Right-click on the file and select Edit script or Show more options > Edit script.
- Enter the following script:
#IfWinActive ahk_class ConsoleWindowClass ^L:: Send cls{Enter} return #IfWinActive
- Press Ctrl + S to save the file and then close it.
- Double-click on the file to run it.
Now you can use the Ctrl + L shortcut to clear the screen on Command Prompt.
- If you want to use any other shortcuts, you need to replace
^L
with the shortcut. - Here,
^
shows the Ctrl key, andL
is the letter you need to press with Ctrl. - You can open the AutoHotkey app on your system and click on create a script file to search how to use other keys as hotkeys.
You can also place this script on the Startup folder to auto-run it after login. To do so,
- Open Run and enter
shell:startup
to open the Startup folder. - Copy or move the
.ahk
script to this location.
How to Clear Current Line on Command Prompt?
Sometimes, you may enter the wrong command on the prompt. In such cases, you may want to clear the entire line instantly instead of pressing Backspace for a long time. It might also be better to quickly clear some parts of the line instead of the whole line.
You can use the following keys or hotkeys to perform such tasks on Command Prompt:
- Escape (Esc) – It clears the current input line.
- Ctrl + C – It abandons the current input line and moves the cursor to a new black line. It also exits any command that you are currently running, returning you back to the prompt line.
- Ctrl + Home – Clears everything in from of the cursor on the current input line.
- Ctrl + End – Clears everything to the right of the cursor on the current input line.
- Ctrl + Backspace – Delete a single word just before the cursor on the current input line.
How to Clear Command History on Command Prompt?
Command Prompt saves a history of the previous commands you entered in the same session. You can press the up arrow key to call the previous command and together with the down key, you can cycle through this command history.
If you want to clear this history, you can do it easily by pressing Alt + F7 on the Command Prompt.