Guides

How to clear the terminal in Linux: clear, Ctrl+L, reset and the scrollback

Clear terminal screens in Linux with clear or Ctrl+L, keep or wipe the scrollback, fix a garbled terminal with reset, and clear bash history properly.

Published ~6 min read
On this page

Short answer: type clear or press Ctrl+L to clear the terminal in Linux and macOS. clear also wipes the scrollback where the terminal supports it, while clear -x and Ctrl+L keep it. If the screen shows garbage after printing a binary file, type reset. On Windows, use cls in cmd and Clear-Host (or cls) in PowerShell.

any Linux terminal
clear              # clear the screen and, if supported, the scrollback
clear -x           # clear the screen, keep the scrollback
reset              # repair a garbled terminal (after cat on a binary file)
history -c && history -w    # clearing bash HISTORY is a different thing, see below

What clear and tput send to the terminal was captured with od on Debian 12 with ncurses 6.4 and bash 5.2.15 on 21 October 2026, and the history cases ran there too. reset and stty sane need a real terminal, so those parts follow their man pages, and the keyboard shortcuts of individual terminal apps follow their documentation; neither was tried in a graphical terminal.

Clear terminal cheat sheet

Command or keyScreenScrollbackWhere
clearClearedCleared if the terminal supports itAny Linux, macOS
clear -xClearedKeptncurses clear
Ctrl+LCleared, current line keptKeptbash, zsh and most shells
Esc, then Ctrl+LClearedCleared if supportedRecent bash (5.2 here)
tput clearClearedSame as clearScripts
printf '\033c'Full terminal resetDepends on the terminalScripts, quick fix
resetReset and redrawnDepends on the terminalGarbled terminal
clsClearedDepends on the consoleWindows cmd
Clear-HostClearedDepends on the consolePowerShell (aliases cls, and clear on Windows)

clear vs Ctrl+L

clear looks up your terminal type in $TERM, asks the terminfo database for the right control sequence and prints it. For the common xterm-256color it sent three:

Debian 12 · TERM=xterm-256color
$ clear | od -c
0000000 033   [   H 033   [   2   J 033   [   3   J
$ clear -x | od -c
0000000 033   [   H 033   [   2   J

\033[H moves the cursor home, \033[2J erases the screen, and \033[3J erases the scrollback. The last one is the extended E3 capability, which the ncurses man page describes as an xterm extension that PuTTY and the Linux console adopted later. clear -x leaves it out, so your earlier output is still there when you scroll up. Terminal types without E3 never clear scrollback: with TERM=screen-256color, clear sent only \033[H\033[J, cursor home and erase, and no \033[3J.

Ctrl+L is not a command but a key binding of the shell’s line editor. In bash it runs clear-screen: the screen is cleared, the line you were typing stays at the top, and the scrollback is kept. bash 5.2 also binds Esc followed by Ctrl+L to clear-display, which the bash manual describes as clearing the screen and, if possible, the scrollback buffer too. zsh binds Ctrl+L to its own clear-screen, and many full-screen programs, such as less, use it to redraw.

When clear does nothing

Debian 12
$ env -u TERM clear; echo $?
TERM environment variable not set.
1
$ TERM=dumb clear; echo $?
1

Without a usable $TERM, clear cannot know what to send. That happens in cron jobs, in some CI logs and in minimal containers. In a script, clear only when the output really is a terminal: [ -t 1 ] && clear.

Clear the scrollback in tmux, screen and terminal apps

Scrollback lives in whatever program draws the text: the terminal app on your computer, or a multiplexer in between. clear only reaches the layer that understands its sequence.

  • tmux keeps its own history per pane. The tmux manual lists clear-history for it, so clear && tmux clear-history empties both the screen and the pane history. The tmux cheat sheet covers the scrolling side.
  • GNU screen: per its man page, Ctrl-a C clears the window and saves what was on it into the scrollback buffer, so it hides old output rather than deleting it. The screen guide explains copy mode.
  • PuTTY: the window menu (click the icon at the top left) has Clear Scrollback and Reset Terminal.
  • macOS Terminal: Cmd+K clears the screen and scrollback.
  • GNOME Terminal: the Terminal menu has Reset and Clear.

Over SSH, all of this happens on your side. The server only sends the escape sequences; whether the scrollback goes away depends on the terminal you connect with, which is why the same clear behaves differently in PuTTY and in another client. The PuTTY guide covers its settings.

Fix a garbled terminal with reset

cat on a binary file, or a program that crashes mid-screen, sends bytes that the terminal reads as commands. One of them, \033(0 (listed as smacs in the xterm terminfo entry), switches to the line-drawing character set, so everything you type afterwards looks like boxes and lines. A program that dies while it has echo switched off, such as an editor or a password prompt, leaves you typing blind. clear undoes neither. reset does: per its man page it sets the terminal modes back to sane values and sends the terminal’s reset strings, which for xterm-256color begin with the full reset \033c.

any Linux
reset          # type it even if you cannot see the letters, then Enter
stty sane      # modes only (echo, line editing), no screen reset
tput reset     # the same reset, run through tput

tput clear and printf in scripts

tput clear asks terminfo for the same sequence that clear uses; with ncurses 6.4 it sent all three parts, E3 included. printf '\033c' sends the RIS (reset to initial state) sequence directly, without terminfo. It works on almost every terminal, but it also resets colours, tab stops and character sets, and whether it drops the scrollback depends on the terminal. For a menu script that redraws itself, tput clear or printf '\033[H\033[2J' is the lighter choice. Keep either out of output that goes to a log file, where it only adds junk bytes.

Clearing bash history is a different thing

clear removes text from the screen; the commands you typed are still in the shell’s history (up arrow, history) and in ~/.bash_history. To remove those:

bash
history -c && history -w    # empty this shell's list AND overwrite the file with it
history -d 120              # delete one entry by its number
history -d 120-125          # delete a range (works in bash 5.2)
unset HISTFILE              # do not save anything from this session

history -c alone is not enough on Debian and Ubuntu. Their default ~/.bashrc sets shopt -s histappend, so bash appends to the file on exit instead of rewriting it. In the test, two old lines were still in the history file after history -c and exit; after history -c followed by history -w they were gone. Other open sessions write their own history when they close, so clear those too, or close them first.

The same default ~/.bashrc sets HISTCONTROL=ignoreboth, which includes ignorespace: a command typed with a leading space is not saved at all, which was confirmed by typing echo hidden-with-space after a space. A password that ended up in the history may already have been written to disk, so change it as well.

Windows: cls and Clear-Host

cmd.exe
cls
PowerShell
Clear-Host   # cls works too, and clear on Windows

Per Microsoft’s Clear-Host reference, PowerShell defines cls as an alias on every platform and clear only on Windows; in PowerShell on Linux, clear runs the ncurses program described above. Clear-Host only changes the display: variables, functions and command history stay as they are.

On a server over SSH

On a Linux VPS running Debian or Ubuntu, clear, tput and reset belong to ncurses-bin, a package marked essential that is always installed, and Ctrl+L works in the default bash shell. If you keep long-running work in tmux or screen, remember that their scrollback is separate from your terminal’s. For the rest of the everyday commands, see the Linux commands cheat sheet.

Frequently asked

What is the difference between clear and Ctrl+L?

clear is a program that prints the terminal's clear sequence and, where the terminal type has the E3 capability, also erases the scrollback. Ctrl+L is a shell key binding that clears the screen but keeps the line you are typing and the scrollback, like clear -x.

How do I fix a terminal that shows strange symbols after cat on a binary file?

Type reset and press Enter, even if you cannot read what you type. It sets the terminal modes back to sane values and sends the terminal's reset strings. If Enter does not work, press Ctrl+J, type reset, then press Ctrl+J again.

Does clear delete my bash history?

No, clear only empties the screen. To remove the commands, run history -c && history -w. history -c alone clears only the current shell's list, and on Debian and Ubuntu the old lines stay in ~/.bash_history because their default ~/.bashrc sets histappend.

How do I clear the screen in Windows?

Use cls in Command Prompt. In PowerShell use Clear-Host or its alias cls, which works on every platform; on Windows, clear is an alias for Clear-Host as well.

Related articles

All guides