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’re able to 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.
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 adoskeycommand, which you’re able to 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:
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.cmdfile and including the file in a system path location.
Here are the necessary steps for this process:
Now, you can entercor the substitute letter of your choice on Prompt and clear the screen anytime you want.
Using PowerShell’s Clear-Host Command
Windows PowerShelluses theClear-Host cmdletas an alternative to Command Prompt’s CLS command. So, you can also enterpowershell clear-hostin place ofclsto 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.
Now you may use the Ctrl + L shortcut to clear the screen on Command Prompt.
you may also place this script on the Startup folder to auto-run it after login. To do so,
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:
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 pressingAlt + F7on the Command Prompt.