Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท System Information

Linux clear and reset commands

Reference for clear and reset: wipe the terminal screen, keep or drop scrollback, repair a garbled terminal, and see which escape sequences each one sends.

clear wipes the visible part of the terminal and moves the cursor to the top-left corner. It does this by looking up your terminal type in the terminfo database and printing the escape sequence that terminal understands. Nothing is "deleted" in a file sense: clear only prints a few control characters.

reset is the heavier tool. It re-initializes the terminal completely (modes, character sets, tab stops), which is the cure for a terminal that prints garbage after you accidentally cat a binary file. Both commands normally ship with the ncurses package.

Terminal
clear [-T TYPE] [-V] [-x]
reset [-IQVcqs] [-e CH] [-i CH] [-k CH] [-m MAPPING] [-r] [-w] [-T TYPE]

Try it

Bash What clear really prints

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Terminal type decides the sequence

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
clear [-T type] [-V] [-x]
reset [options]
Name Description
-T type Use the named terminal type instead of the value of $TERM.
-V Print the ncurses version and exit.
-x (clear) Do not erase the scrollback buffer, only the visible screen.
-q (reset) Print the terminal type only; do not initialize anything.
-Q (reset) Do not print the "Erase is ..." and "Kill is ..." messages.
-I (reset) Skip sending initialization strings (useful when they upset the terminal).
-e CH, -i CH, -k CH (reset) Set the erase, interrupt or kill character.
-s (reset) Print the shell commands that set TERM and TERMCAP, for use with eval.

Returns: 0 on success; non-zero if the terminal type is unknown or TERM is not set.

Errors and edge cases: with no TERM in the environment, clear prints an error such as "TERM environment variable not set". Redirecting output to a file stores the raw escape bytes, not an empty screen.

Usage notes

  • Keyboard shortcut. In Bash and most readline-based shells, Ctrl+L does the same as clear and also keeps what you have typed on the line.
  • Scrollback. Modern ncurses clear also erases the scrollback buffer (the E3 capability). Use clear -x or Ctrl+L to keep it. Some terminal emulators ignore the scrollback request.
  • Not a security tool. clear hides text; it does not remove it from the terminal's memory, from script recordings or from your shell history. Secrets typed on a command line stay in history until you delete them (see history).
  • When to use reset. After output of a binary file, after stty experiments, or when typed characters do not echo. If the screen is so broken you cannot read what you type, type reset blindly and press Enter (or Ctrl+J, which works even when Enter is broken).
  • reset is slower. It can take a second or more, and in a remote session it may briefly flicker. Prefer clear for everyday use.
  • Scripts. Call clear only when stdout is a terminal ([ -t 1 ] && clear); otherwise the escape bytes pollute pipes and log files.
  • Lower level. tput can emit the same sequences (tput clear, tput reset, tput sgr0) and is the better building block for your own terminal effects.