If you are asking, “How do I clear Zsh?”, you usually want to remove the text currently displayed in your terminal. The quickest way is to type clear and press Enter, or use the keyboard shortcut Ctrl+L. Both work in most Zsh terminals, including Terminal on macOS and common Linux terminal apps.
It helps to know that Zsh is the shell that reads your commands, while your terminal app displays them. Clearing the screen, clearing terminal scrollback, fixing a garbled display, and deleting command history are different tasks. This guide explains which command to use for each one.
The quickest way to clear the Zsh screen
At the Zsh prompt, run:
clear
Press Enter, and the terminal will clear the visible screen and return you to a fresh prompt. The command does not delete files, stop running processes, or remove your command history. It simply asks the terminal to clear its display.
You can also use the keyboard shortcut Ctrl+L. Hold down Control and press L. In most Zsh setups, this runs a Zsh line-editor action that clears the visible screen and redraws your prompt. It is often the fastest option when you want to clear the terminal without typing a command.
If Ctrl+L does not work, try clear. Keyboard shortcuts can vary because of your terminal app, Zsh configuration, or custom key bindings.
What does the clear command actually remove?
The clear command clears what you can currently see in the terminal window. It does not necessarily erase the terminal’s scrollback buffer. The scrollback buffer is the stored output you can revisit by scrolling up or using your terminal’s search feature.
For example, after running clear, you may see a blank screen, but scrolling upward could still reveal earlier commands and output. That is normal. Zsh is not responsible for keeping or deleting this scrollback; the terminal application manages it.
The distinction matters if you are clearing the screen for tidiness versus trying to hide sensitive output. If you only need a clean workspace, clear is usually enough. If you need to remove visible scrollback, use your terminal app’s scrollback-clearing option as well.
How to clear terminal scrollback
Many terminal applications provide a menu option or keyboard shortcut to clear the scrollback buffer. The exact name and location vary. Look in menus such as View, Terminal, or Shell for an option like “Clear Scrollback,” “Clear Scrollback Buffer,” or “Reset and Clear.” Some apps also let you set a custom shortcut.
On terminals that support the relevant xterm control sequence, you can try:
clear
printf '\033[3J'
The first command clears the visible screen. The second sends a request to erase scrollback in terminals that recognize that sequence. Support differs by terminal, so this may not work everywhere. For the most dependable result, use the clear-scrollback feature built into your terminal app.
Clearing scrollback does not delete your Zsh history file. It only affects text retained by the terminal window, and it may not remove data recorded by terminal logging, screen-recording tools, or system auditing software.
Clear the screen without using the clear command
If clear is unavailable or you want a simple alternative, you can send a basic terminal escape sequence:
printf '\033[2J\033[H'
This asks many terminals to erase the visible display and move the cursor to the top-left corner. It does not reliably clear scrollback, and terminal support can vary. In everyday use, clear or Ctrl+L is generally easier and more portable.
You can also close the terminal tab or window and open a new one. That gives you a fresh display, but it may terminate any foreground process running in that session. Save your work and check for active commands before closing the window.
What to do if clear does not work
If typing clear produces an error or does not clear the screen, check the following:
-
Confirm the command is available. Run
command -v clearto see whether your system can find it. -
Check whether Zsh changed its behavior. Run
whence -v clearto see whetherclearis an alias, function, or executable. -
Try the keyboard shortcut. Press
Ctrl+L; it may still work even if the externalclearcommand is missing. -
Check the terminal type. The
TERMenvironment variable tells programs what kind of terminal they are using. A mismatched value can cause display commands to behave incorrectly. - Open a fresh terminal session. This can help distinguish a terminal-display issue from a problem in your Zsh configuration.
You can inspect the terminal type with:
echo $TERM
A common value is xterm-256color, but the correct value depends on your terminal app and environment. Avoid changing TERM at random: choosing an unsupported value can make colors, screen clearing, and other terminal features behave worse.
When to use reset instead of clear
If the terminal is garbled—for example, text appears in the wrong place, characters are unreadable, or the display does not redraw correctly—clear may not solve the problem. Try:
reset
The reset command attempts to reinitialize the terminal and restore a usable display. Depending on the terminal, it may clear the screen, take a moment to run, or affect display settings. It is intended for recovering from terminal-state problems, not for routine screen clearing.
Use clear for a clean screen. Use reset when the terminal itself seems out of sync or corrupted. Neither command should be treated as a way to erase Zsh command history.
Does clearing Zsh delete command history?
No. The clear command and Ctrl+L clear the display, not your saved commands. Zsh commonly stores command history in a file named .zsh_history in your home directory, although the location can be changed through the HISTFILE setting. You can view the configured path with:
echo $HISTFILE
To remove saved history, you need to handle the history file separately. First, close other Zsh sessions that might still write history. Then remove the configured history file—for example:
rm -f ~/.zsh_history
Only use that example if your history file is actually ~/.zsh_history. If echo $HISTFILE shows a different path, use the correct file instead. A running Zsh session may still have commands in memory and could write them back when it exits. For that reason, close sessions before deleting the file, then open a new shell and verify the result.
Deleting the history file is not the same as securely erasing every record of a command. Commands may also appear in terminal scrollback, shell logs, backups, or other monitoring tools. If your goal is to remove sensitive information, consider those sources too, and avoid entering secrets directly into shell commands whenever possible.
Make clearing the terminal part of your Zsh workflow
For everyday use, memorize Ctrl+L as the quick way to clear the Zsh screen. Use clear when you prefer a command, want to include screen clearing in a script, or need a command that is easy to remember.
You can also create a short alias, although it is usually unnecessary because clear is already brief. To define an alias for the current session, for example, run:
alias c='clear'
After that, typing c at the prompt runs clear. To keep the alias between sessions, add it to your Zsh startup configuration, commonly ~/.zshrc, and start a new shell or reload the file:
source ~/.zshrc
Aliases are optional conveniences. If a custom alias or function named clear causes unexpected behavior, inspect it with whence -v clear and adjust your configuration if needed.
Quick answers: clearing Zsh
-
How do I clear the Zsh screen? Run
clearor pressCtrl+L. -
How do I remove terminal scrollback? Use your terminal app’s “Clear Scrollback” option;
clearalone may not do it. -
How do I fix a garbled terminal? Try
resetafter saving any important work. - Does clearing the screen delete command history? No. Screen contents, scrollback, and Zsh history are separate.
-
How do I check where Zsh saves history? Run
echo $HISTFILE.
Conclusion
To clear Zsh quickly, type clear or press Ctrl+L. These options clear the visible terminal screen, while scrollback is controlled by your terminal app and command history is stored separately by Zsh. Use the terminal’s scrollback controls when you want to remove earlier displayed output, and use reset only when the terminal display is malfunctioning. Knowing which kind of “clear” you need helps you choose the right fix without accidentally affecting running work or saved history.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.