Loading...
X

How to clear the terminal window in PowerShell. Analog of clear

When debugging cmdlets and options, so that previously output data does not fall into the field of view and does not mix with the results of the last command, or if for other reasons you want to delete everything that the command line utilities output, then you can use this instruction.

We will consider such questions as:

1) How to delete everything that is output to the terminal using a command

2) How to clear the contents of the screen in a script

3) How to clear the terminal using a keyboard shortcut

Of course, you can always close the terminal window and then open it again. But this will take longer than the methods shown below. In addition, closing and opening the terminal also has other consequences – if you assigned values ​​to any variables, then all this data is cleared. If you need exactly this effect (clearing all variable values), then closing and then opening the terminal is more suitable for you. In all other cases, you can delete all output in the command line using cmdlets or a keyboard shortcut.

How to delete everything output to the terminal using a command

You can use a cmdlet to clear the terminal window:

Clear-Host

This command will clear everything the user inputed and everything the utilities output. The Clear-Host cmdlet itself will also be removed from the screen.

This command has aliases:

clear

cls

That is, if you want to clear the terminal, you can use any of these commands – in PowerShell, they are all equivalent.

How to clear the contents of the screen in a script

With the same command, you can clear the window directly in the script, for example, to remove unnecessary data so that it does not distract the user.

Clear-Host

Keyboard shortcut for clearing the terminal window

Windows Terminal supports the Ctrl+L key combination – this is the fastest way to clear the command line window.

The Ctrl+L key combination also works in many other terminals, including Linux. You can use this knowledge in other operating systems as well.


Leave Your Observation

Your email address will not be published. Required fields are marked *