- Command to clear the Command Prompt screen:
CLS
- Shortcut key to clear the Command Prompt history: Alt+F7
- Cmdlet to clear the PowerShell window screen:
Clear-Host
- Command to clear PowerShell history:
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
CMD and PowerShell tools are primarily used for system administration, automation, and troubleshooting. However, entering multiple commands one after another can make the screen messy. Sometimes, we need to declutter the command window screen and start fresh. In this article, we’ll show you how to clear the command history screen in PowerShell and Command Prompt in Windows 10 and 11.
Clearing the command history in PowerShell and Command Prompt is essential for improving readability, avoiding confusion, maintaining privacy, and establishing a clear workflow in command-line interfaces.
Before we learn the methods to clear the command screen in PowerShell, let’s check out the basics of command history. PowerShell keeps track of commands entered into the shell. This history of commands can be viewed and accessed in several ways.
- Up and down arrow keys: Pressing the up arrow key will cycle through your previously entered commands, allowing you to quickly access and reuse them.
- Get-History cmdlet: The Get-History cmdlet allows you to view a list of all the PowerShell commands used entered during your current session. This can be useful if you have to refer back to a specific command or if you want to see a list of all the commands you have entered so far.
- Invoke-History cmdlet: The Invoke-History cmdlet allows you to rerun a specific command from your command history without typing it out again. Using the ID number associated with the command in your history list will rerun the command with an ID of 23 from your history list.
Example: Invoke-History -ID 23
Clearing the Command Screen in PowerShell
It is easy to clear the commands and their outputs in the current PowerShell session using PowerShell cmdlets (their aliases) and keyboard shortcuts.
Clear PowerShell Screen
Type the following cmdlet in PowerShell and hit Enter.
Clear-Host
This will clear the command window screen as shown below.
Alternatively, you can use the aliases of the Clear-Host
cmdlet to clear the PowerShell console. Simply type “cls“, “cls /?” or “clear” and hit Enter in the PowerShell window. This will remove all previous commands and outputs from the screen so that you start afresh with new tasks.
Moreover, you can also use keyboard shortcuts to clear the PowerShell screen in Windows 10 and 11. Pressing “Ctrl + L” on your keyboard will have the same effect as executing Clear-Host
.
Clear PowerShell Command History
While Clear-Host
 clears the current console, the Clear-History
cmdlet and Alt+F7 are used to clear the command history in PowerShell. If the PowerShell’s Clear-History is not working for you and it doesn’t clear the command history, it’s because PowerShell’s history is saved in a text file named ‘ConsoleHost_history.txt‘ at the following location.
C:\Users\user\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\
Use the following command to get the location of the command history text file in Windows 10 and 11.
(Get-PSReadlineOption).HistorySavePath
You can either navigate to the above location on your PC and remove the contents of the ‘ConsoleHost_history.txt’ file, or execute the following command to clear the command history in PowerShell.
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
You can also instruct PowerShell not to save the command history in the ‘ConsoleHost_history.txt’ at all.
Set-PSReadLineOption -HistorySaveStyle SaveNothing
To enable the saving of command history to the text file, use this command:
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Clearing CMD Screen and History in Command Prompt
Clear Command Prompt Screen
You can clear a single line or everything from the Command Prompt screen and start with a clean slate.
To clear the Command Prompt screen on your Windows 10/11 PC, type cls
or CLS
in the command window and press Enter.
Here are a few shortcut keys to help you while using the Command Prompt:
- Esc or Escape: If you type a wrong command by mistake, you can quickly clear the line from the CMD window screen by pressing the Esc key.
- Ctrl + Backspace: Deletes one left to the cursor.
- Ctrl + C: Leave the line you are typing or terminate the command in process and start with a new prompt.
- Alt+F4: Close an open PowerShell or Command Prompt window.
Clear the Command Prompt History
Command history is a useful feature in the Command Prompt. It allows you to access your past commands quickly and reuse them when needed. You can view the commands used in the current session in two ways:
- Up and down arrow keys: Cycle through your previously entered commands.
- F7: Shows the list of commands used in the CMD. You can use the up and down arrow keys to highlight the commands and press Enter to use them.
If you want to clear the Command prompt history on Windows 10/11, press Alt+F7. That’s it! The command history will be cleared.
Using the “cls
” command in Command Prompt and the “Clear-Host
” cmdlet in PowerShell are simple ways to clear your screen and declutter your workspace. With these tips, you can effectively use clear screen commands and improve your productivity while working with PowerShell and Command Prompt.
Read Next: 3 Ways to Replace PowerShell with Command Prompt