LinuxCommandLibrary

reset

Reinitialize the terminal to its default state

TLDR

Reinitialize the current terminal

$ reset
copy

Display the terminal type instead
$ reset -q
copy

SYNOPSIS

reset [-IQKP]

PARAMETERS

-I
    Re-initializes the terminal. This is equivalent to invoking 'tput init', which sends the terminal's initialization strings from the terminfo database.

-Q
    Causes 'reset' to output both the 'init' string (initialization) and the 'reset' string from the terminfo database. Useful for a more comprehensive reset.

-K
    Resets the terminal's keypad. This sends the 'keypad_normal' (kcrmn) string from the terminfo database, restoring the keypad to its normal (non-application) mode.

-P
    Resets the terminal's programmable function keys. This sends the 'keypad_xmit' (kf) string, which often sets function keys to their default behaviors.

DESCRIPTION

The `reset` command is a utility designed to restore a terminal's state to a known, default configuration. It is invaluable when a terminal session becomes garbled, unresponsive, or exhibits strange behavior due to misconfigured programs, incorrect control sequences, or the accidental display of binary files.

Essentially, `reset` sends a series of initialization and reset sequences from the `terminfo` database, specific to the terminal type defined by the `TERM` environment variable. These sequences typically clear the screen, reset tab stops, disable special character mappings (like raw mode), re-enable echoing of characters, and restore standard cursor and display attributes.

While often appearing as a standalone command, `reset` is commonly a hard link to or an alias for `tput reset` or `tput init`, leveraging the capabilities of the `ncurses` library to interact with the terminal's control sequences. It's a quick fix to get your terminal back to a usable state without needing to close and reopen the session.

CAVEATS

  • `reset` relies on the correct `TERM` environment variable being set. If `TERM` is incorrect, `reset` might send inappropriate sequences, potentially worsening the terminal state or having no effect.
  • While `reset` aims to restore a sane state, some extremely malformed terminal states might not be fully recoverable without closing and reopening the terminal session.
  • It typically clears the entire screen, which can wipe out previous command output or scrollback history in some terminal emulators.

COMMON USAGE SCENARIOS

The `reset` command is most frequently used in situations where your terminal display becomes unreadable or unresponsive. This often happens after:
• Accidentally displaying a binary file: Using `cat` on an executable or image file can print non-printable characters that alter terminal settings.
• A program crashes or exits improperly: Some applications may leave the terminal in a raw input mode, or change character sets, making further interaction difficult.
• Incorrect terminal settings applied: Sometimes, a script or misconfiguration can apply incorrect escape sequences.

RELATIONSHIP WITH TERM VARIABLE

The effectiveness of `reset` heavily depends on the `TERM` environment variable. This variable tells the system what type of terminal you are using (e.g., `xterm`, `linux`, `vt100`). `reset` (via `tput`) consults the `terminfo` database for the initialization and reset sequences specific to the `TERM` type. If `TERM` is unset or set incorrectly, `reset` may fail to properly restore the terminal.

HISTORY

The `reset` command is an integral part of the `ncurses` (new curses) library, which provides a powerful and portable way to write text-based user interfaces. Its origins are tied to the need for robust terminal control in Unix-like systems. Historically, `reset` often existed as a standalone executable, frequently implemented as a hard link to `tput`. This approach allows `reset` to leverage `tput`'s ability to query and apply terminal capabilities defined in the `terminfo` database, ensuring compatibility across a vast array of terminal types and emulators. Its continued relevance highlights the persistent challenge of managing diverse terminal control sequences in modern computing environments.

SEE ALSO

tput(1), stty(1), clear(1), setterm(1), terminfo(5)

Copied to clipboard