To clear a terminal window, use the command that matches your operating system and shell. On Linux and macOS, type clear and press Enter. In Windows Command Prompt or PowerShell, type cls and press Enter. You can also use a keyboard shortcut: Ctrl+L works in many terminal apps and shells. These methods clear the visible screen, but they usually do not erase your command history or securely delete information from your computer.
How to Clear a Terminal on Linux and macOS
The simplest way to clear a terminal on most Linux distributions and macOS is to enter the clear command:
clear
Press Enter, and the current display will be cleared so you can work from a fresh-looking prompt. The command is available in many common shells, including Bash and Zsh, and works in most terminal applications.
You can also press Ctrl+L. In many shells, this keyboard shortcut redraws the prompt at the top of the terminal and moves earlier output out of the visible area. It is a quick option when you want to tidy the screen without typing a command. The exact behavior may vary depending on your shell, terminal app, or customized keyboard shortcuts.
If you want to clear the screen and move the cursor to the top-left corner, another option is:
printf '\033[2J\033[H'
This sends control characters that clear the display and reposition the cursor. Most people do not need this command for everyday use; clear is easier to remember. The control-character method can be useful in scripts or when the clear command is unavailable.
How to Clear a Terminal in Windows
In Windows Command Prompt, type cls and press Enter to clear the terminal screen:
cls
The same command works in Windows PowerShell. It is the familiar Windows alternative to the clear command used on Linux and macOS. In PowerShell, Clear-Host is also available; cls is a built-in alias for it.
Depending on the terminal app and shell, Ctrl+L may clear or redraw the display too. For a predictable result in Command Prompt or PowerShell, use cls. If you are running a Linux shell through Windows Subsystem for Linux (WSL), use clear instead, just as you would in a Linux terminal.
Windows Terminal is an app that can host different shells, such as PowerShell, Command Prompt, and WSL. The command you need depends on the shell running in the tab, not simply on the name of the terminal app.
What Does “Clear the Terminal” Actually Do?
Clearing a terminal usually removes text from the visible screen or moves it out of view. It does not normally remove files, stop a running program, or erase the commands you have entered. The command history is generally stored separately by the shell, and earlier terminal output may still be available by scrolling up.
It helps to distinguish between the terminal app and the shell. The terminal app displays text and provides the window or tab. The shell, such as Bash, Zsh, PowerShell, or Command Prompt, interprets commands. Some clearing methods are shell commands, while others are keyboard shortcuts handled by the shell or terminal app.
-
Clear the visible screen: Use
clear,cls, or a supported keyboard shortcut. - Clear scrollback: Remove or hide text you could otherwise view by scrolling up. The method depends on your terminal app.
- Clear command history: Remove saved or session commands. This is separate from clearing the display.
- Reset the terminal: Restore terminal behavior if it is displaying garbled text or acting strangely. This is more extensive than clearing the screen.
How to Clear Terminal Scrollback
After running clear, you may still be able to scroll up and see earlier output. That is because many terminal apps keep a scrollback buffer: a record of text displayed before the current screen. Clearing the display and clearing this buffer are not always the same operation.
Some terminal emulators provide a menu option such as “Clear Scrollback,” “Clear Buffer,” or “Clear Screen and Scrollback.” The label and location vary by app. Check the terminal’s menus, settings, or keyboard-shortcut preferences for the relevant option.
In many compatible terminals, this command clears the display and scrollback buffer:
printf '\033[3J\033[H\033[2J'
Support for the scrollback control sequence varies, so the command may not work in every terminal. If your goal is simply to make the current window easier to read, the standard clear or cls command is usually enough. If you are handling sensitive output, do not assume that clearing the screen securely erases it from logs, terminal recordings, or other system records.
How to Clear the Terminal Without Losing Your Work
Clearing the terminal screen does not normally interrupt a command that is already running. It only changes what is displayed. You can typically run clear or cls after a command finishes, or use a supported shortcut while working in the shell.
If a command is still producing output, clearing the screen may not stop it; new output can immediately appear again. To stop a foreground command, Ctrl+C is commonly used in Unix-like shells and Windows terminals, but it sends an interrupt to the running process. Use it only when you intend to stop that command. It is not a terminal-clearing shortcut.
To keep useful output before clearing the display, save it to a file or copy it first. For example, you can redirect a command’s output to a file with a command such as your-command > output.txt. Replace your-command with the program you want to run. Be aware that a single greater-than sign can overwrite an existing file with the same name.
How to Clear a Terminal in VS Code and Other IDEs
Integrated development environments often include a terminal panel, but the commands depend on the shell selected for that panel. In a VS Code terminal running Bash, Zsh, or WSL, use clear. In a panel running PowerShell or Command Prompt, use cls.
Many IDEs also offer a clear button or a command in the terminal panel’s menu. This can be convenient when you want to clear the display without changing tabs or typing a command. Look for a trash-can, clear, or terminal-actions icon, and check the application’s keyboard-shortcut settings if you want a dedicated shortcut.
IDE terminal panels may handle scrollback differently from standalone terminal apps. If earlier output remains visible when you scroll, use the panel’s clear option or adjust its scrollback settings. Clearing a terminal panel does not usually clear the IDE’s output window, debug console, or application logs; those are separate views.
How to Clear a Terminal Over SSH
When connected to a remote computer over SSH, you can usually clear the remote session’s display with clear, just as you would in a local Linux or macOS shell. The command runs in the remote shell, while the terminal app on your computer displays the result.
If clear produces an error or does not display correctly, the remote session may have an incorrect terminal setting. The TERM environment variable describes terminal capabilities, and an inaccurate value can affect screen-clearing behavior and other display features. If you are unsure how to change it, ask your system administrator or check the documentation for your terminal app and remote system.
Keep in mind that clearing an SSH window does not erase remote shell history, server logs, or files. It only affects the display and, depending on the method, possibly the terminal’s scrollback buffer.
What If the Clear Command Does Not Work?
If you type clear and see a “command not found” message, first check which shell you are using. In Windows Command Prompt, try cls. In PowerShell, cls or Clear-Host should work. In a Linux or macOS shell, make sure the command is typed correctly and that the environment has access to the standard system utilities.
If the screen clears but immediately fills again, a command may still be running and printing output. Stop it only if appropriate, or wait for it to finish before clearing the display. If the text is garbled, the terminal may need to be reset. On many Unix-like systems, you can try:
reset
Unlike clear, reset can reinitialize terminal settings and may redraw the screen. It can also change the current display behavior, so use it when a simple clear does not resolve a display problem.
For a shortcut that does nothing, check the terminal app’s keyboard settings and the active shell. Shortcuts can be intercepted by the operating system, customized by the app, or assigned a different action.
Does Clearing a Terminal Delete Command History?
No. Clearing the terminal screen generally does not delete shell history. Bash and Zsh, for example, can keep commands in history files, while PowerShell maintains its own history behavior. The precise storage and session behavior depend on the shell and configuration.
If you need to remove a command from history, use the appropriate history-management feature for your shell and understand whether it affects only the current session or also saved history. Clearing visible text is not a privacy or data-erasure method. Sensitive information may also remain in application logs, recordings, copied text, or system files.
Quick Reference: Terminal Clear Commands
-
Linux: Type
clear, or tryCtrl+L. -
macOS: Type
clear, or tryCtrl+L. -
Windows Command Prompt: Type
cls. -
Windows PowerShell: Type
clsorClear-Host. -
Windows Subsystem for Linux: Type
clearin the Linux shell. - Terminal scrollback: Use your terminal app’s clear-scrollback option if available.
Conclusion
For most situations, clearing a terminal is simple: use clear on Linux and macOS, or cls in Windows Command Prompt and PowerShell. A shortcut such as Ctrl+L may also work. If you need to remove earlier output from the scrollback buffer, use your terminal app’s dedicated option, since clearing the visible screen alone may not remove it.
Remember that clearing the display does not usually erase command history, stop a running program, or securely delete data. Choose the method that matches what you want to clear, and check which shell is active when a command does not work.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.