cls - Clear Screen
What is the cls
Command?
The cls
command stands for “Clear Screen” and is used to clear the screen in the command prompt. When you use this command, all currently displayed text is erased, and the prompt moves to the top left of the screen.
Clearing the screen can help you organize your workspace by removing past commands and outputs, making it easier to start new tasks.
Additionally, you can use the cls
command within batch files or scripts to clear the screen during script execution.
Basic Usage of the cls
Command
cls
This command has no arguments or options and works simply by typing it.
Examples of the cls
Command
As an example, consider clearing the screen after performing some operations.
Hello World!
In the example above, the echo
command is used to display the message Hello World!
.
Next, the cls
command is used to clear the previous command.
Hello World!
This operation clears the screen and displays the prompt again. The initial Microsoft copyright information is also cleared, organizing the screen.
Using in Batch Files
You can use the cls
command in batch files. This allows you to clear the screen during script execution.
例:
@echo off
setlocal
echo Processing...
cls
echo The screen has been cleared.
pause
endlocal
This script first displays a message, clears the screen with the cls
command, and then displays a new message. When the batch file is executed, the initial “Processing…” message will not be visible by the time the pause
command is reached.
In a Linux environment, you can use the clear
command to clear the screen.
Additionally, there is a shortcut key to clear the screen: pressing Ctrl + L
will clear the screen.
Summary
The cls
command in Command Prompt is a very simple yet highly useful tool. By clearing the screen, it helps to organize your work and avoid visual clutter.