There are different ways to clear or wipe the screen in a console. Here are the common methods and the fine differences between them.

Ctrl+L (keyboard shortcut)

Ctrl+l

This is the fastest and most commonly used method. Its effect is essentially the same as the clear command: the screen scrolls up to make room for new input.

The key point is that the previous content is not deleted - you can scroll up with the mouse or PageUp to keep viewing the commands and results that were output before.

clear (command)

clear

This is the standard command for clearing the screen. In many terminal emulators its effect is identical to Ctrl+L, and the history can still be viewed. There are small differences, however: some terminal emulators (KDE) also wipe the scrollback buffer when running clear, so you can no longer scroll up.

Why is that?

Modern clear versions, from 2013 onward in the ncurses package, send a special escape sequence (\033[3J) that the console interprets as “also delete the scrollback buffer.” \033[2J only clears the screen. With a preceding \033[H, the cursor is placed in the top line.

echo -e "\033[H\033[2J"

Double clear

clear && clear

If you have the classic clear command that does not wipe the buffer, you can still clear the buffer by calling the clear command again right after. For example clear && clear.

Even so, this is faster than reset and sufficient for everyday use.

reset (command)

reset

This is a “thorough” repair measure. It not only clears the screen but fully resets the internal state of the terminal. If your terminal is “acting up” (e.g. characters appear in the wrong positions, the Enter key no longer moves to a new line, or the font color is scrambled), reset fixes these problems. Because the terminal has to be reinitialized, it runs slower than the other two methods.

Note: running reset can leave you unable to scroll up to view the previous history.

tput (commands)

What is tput

tput is a tool with parameters and so-called capability codes for controlling terminal capabilities.

Parameters

  • -T: Specifies the terminal type and overrides the TERM environment variable. In most cases this is not necessary.
  • -S: Allows multiple capability codes to be entered via standard input (one per line), which is suitable for batch processing.
  • -x: An option of the ncurses version that specifically prevents tput clear from wiping the scrollback buffer (relevant to your earlier problem).

Capability Modes

Capability modes or capability codes are not command-line options in the strict sense, but rather the “parameters” passed to tput, e.g. tput clear, tput cup 10 10, tput bold, which can change properties on the screen such as font color or background. A complete list can be found in the manpage for terminfo(5).

The official reference is the manpage terminfo(5) - man 5 terminfo.

  • Screen & cursor: clear, cup, home, civis, cnorm, sc, rc, cols, lines
  • Text attributes: bold, dim, smul, rmul, rev, blink, sgr0
  • Colors (ANSI): setaf, setab
  • Delete & insert: el, el1, ed, ech, ich, il, dch, dl

This is only an excerpt. A complete list of all terminfo capability codes is found in the terminfo database, which defines hundreds of capabilities (boolean, numeric, and string capabilities) that also vary by terminal type and implementation.

The terminfo database is a file that exists in readable form (*.src) and in compiled form (*.tic) in the directories /usr/share/terminfo/ or /lib/terminfo/. Each terminal has its own file there, e.g. /usr/share/terminfo/v/vt100). The terminal calls the corresponding function, and the underlying ncurses then looks in this compiled file for the matching escape sequences.

tput clear

tput clear

tput clear: Functionally equivalent to the standard clear command, clears the screen, and the history generally remains intact.

tput reset

tput reset

tput reset works similarly to reset (resets the terminal state), but with a small difference:

The standard reset command (without tput) includes a delay of about 1 second for compatibility with old terminals, while tput reset does not have this delay and responds faster.

Escape sequences

echo -e "\033c"
printf "\033c"

echo -e "\033c" or printf "\033c": This is a hard-coded escape sequence whose effect corresponds to a hard reset of the terminal (similar to tput reset). Since tput looks up the terminfo database, whereas this is hard-coded, it may not work in exotic terminals.

stty sane (rescue for faulty display)

stty sane

Sometimes the terminal is not “dirty” but the mode has been changed (e.g. after accidentally cat-ing a binary file, so that the Enter key no longer works or characters are not displayed).

This command does not clear the screen but resets the terminal settings (such as line wrapping and echo mode) to a “normal” default behavior. If your terminal is “acting up” and reset is too slow, you can try stty sane first to restore the basic input and display logic.

setterm -reset

setterm -reset

This is another tool for terminal control whose reset function is similar to tput reset. Its advantage is that the option names are more intuitive (e.g. -reset), but it is a Linux-specific tool and not POSIX-standardized, so it is usually not available on non-Linux systems (such as BSD or macOS). It is part of the util-linux package: setterm.