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.
clear [-T TYPE] [-V] [-x] reset [-IQVcqs] [-e CH] [-i CH] [-k CH] [-m MAPPING] [-r] [-w] [-T TYPE]
Try it
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.
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
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+Ldoes the same asclearand also keeps what you have typed on the line. - Scrollback. Modern ncurses
clearalso erases the scrollback buffer (theE3capability). Useclear -xorCtrl+Lto keep it. Some terminal emulators ignore the scrollback request. - Not a security tool.
clearhides text; it does not remove it from the terminal's memory, fromscriptrecordings or from your shell history. Secrets typed on a command line stay in history until you delete them (seehistory). - When to use
reset. After output of a binary file, aftersttyexperiments, or when typed characters do not echo. If the screen is so broken you cannot read what you type, typeresetblindly and press Enter (orCtrl+J, which works even when Enter is broken). resetis slower. It can take a second or more, and in a remote session it may briefly flicker. Preferclearfor everyday use.- Scripts. Call
clearonly when stdout is a terminal ([ -t 1 ] && clear); otherwise the escape bytes pollute pipes and log files. - Lower level.
tputcan emit the same sequences (tput clear,tput reset,tput sgr0) and is the better building block for your own terminal effects.
Related
tput,history,script- Lessons: Shell Basics, Bash Completion and Prompts