# tset - initialize or reset terminal state - man(1) - [phpMan]

> **TLDR:** Initialize or reset terminal state.
>
- Initialize the terminal:
  `tset`
- Set control characters and modes:
  `tset -c`
- Print the terminal type to the (`stderr`) output:
  `tset -r`
- Print shell commands to set the environment:
  `tset -s`
- Resize the terminal window to the detected size:
  `tset -w`

*Source: tldr-pages*

---

[_tset_(1)](https://www.chedong.com/phpMan.php/man/tset/1/markdown)                                     User commands                                    [_tset_(1)](https://www.chedong.com/phpMan.php/man/tset/1/markdown)

## NAME
       **tset**, **reset **- initialize or reset terminal state

## SYNOPSIS
       **tset **[**-IQVcqrsw**] [**-**] [**-e _**ch_] [**-i _**ch_] [**-k _**ch_] [**-m _**mapping_] [_terminal-type_]
       **reset **[**-IQVcqrsw**] [**-**] [**-e _**ch_] [**-i _**ch_] [**-k _**ch_] [**-m _**mapping_] [_terminal-type_]

## DESCRIPTION
   _**tset_ — initialization**
       This program initializes terminals.

       First,  **tset **retrieves the current terminal mode settings for your terminal.  It does this by
       successively testing

       •   the standard error,

       •   standard output,

       •   standard input and

       •   ultimately “/dev/tty”

       to obtain terminal settings.  Having retrieved these settings, **tset **remembers which file  de‐
       scriptor to use when updating settings.

       Next, **tset **determines the type of terminal that you are using.  This determination is done as
       follows, using the first terminal type found.

       1. The **terminal **argument specified on the command line.

       2. The value of the _TERM_ environment variable.

       3.  (BSD systems only.) The terminal type associated with the standard error output device in
       the _/etc/ttys_ file.  (On System V hosts and systems using that convention, [_getty_(8)](https://www.chedong.com/phpMan.php/man/getty/8/markdown) does this
       job by setting _TERM_ according to the type passed to it by _/etc/inittab_.)

       4. The default terminal type, “unknown”, is not suitable for curses applications.

       If the terminal type was not specified on the command-line, the **-m **option mappings  are  then
       applied;  see  subsection  “Terminal Type Mapping”.  Then, if the terminal type begins with a
       question mark (“?”), the user is prompted for confirmation of the terminal  type.   An  empty
       response  confirms the type, or, another type can be entered to specify a new type.  Once the
       terminal type has been determined, the terminal description for the  terminal  is  retrieved.
       If  no  terminal description is found for the type, the user is prompted for another terminal
       type.

       Once the terminal description is retrieved,

       •   if the “**-w**” option is enabled, **tset **may update the terminal's window size.

           If the window size cannot be obtained from the operating system,  but  the  terminal  de‐
           scription  (or  environment, e.g., _LINES_ and _COLUMNS_ variables specify this), use this to
           set the operating system's notion of the window size.

       •   if the “**-c**” option is enabled, the backspace, interrupt and line kill  characters  (among
           many other things) are set

       •   unless  the  “**-I**” option is enabled, the terminal and tab _initialization_ strings are sent
           to the standard error output, and **tset **waits one second (in case a hardware reset was is‐
           sued).

       •   Finally, if the erase, interrupt and line kill characters have changed, or are not set to
           their default values, their values are displayed to the standard error output.

   _**reset_ — reinitialization**
       When invoked as **reset**, **tset **sets the terminal modes to “sane” values:

       •   sets cooked and echo modes,

       •   turns off cbreak and raw modes,

       •   turns on newline translation and

       •   resets any unset special characters to their default values

       before doing the terminal initialization described above.  Also, rather than using the termi‐
       nal _initialization_ strings, it uses the terminal _reset_ strings.

       The **reset **command is useful after a program dies leaving a terminal in an abnormal state:

       •   you may have to type

               _<LF>_**reset_**<LF>_

           (the line-feed character is normally control-J) to get the terminal to work, as carriage-
           return may no longer work in the abnormal state.

       •   Also, the terminal will often not echo the command.

### Setting the Environment
       It is often desirable to enter the terminal type and information about the  terminal's  capa‐
       bilities into the shell's environment.  This is done using the **-s **option.

       When the **-s **option is specified, the commands to enter the information into the shell's envi‐
       ronment are written to the standard output.  If the _SHELL_ environment variable ends in “csh”,
       the  commands  are for [_csh_(1)](https://www.chedong.com/phpMan.php/man/csh/1/markdown), otherwise, they are for [_sh_(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown).  The _csh_ commands set and unset
       the shell variable **noglob**, leaving it unset.  The following line in the  **.login  **or  **.profile**
       files will initialize the environment correctly:

           eval `tset -s options ... `

### Terminal Type Mapping
       When  the terminal is not hardwired into the system (or the current system information is in‐
       correct) the terminal type derived from the _/etc/ttys_ file or the _TERM_  environment  variable
       is  often something generic like **network**, **dialup**, or **unknown**.  When **tset **is used in a startup
       script it is often desirable to provide information about the type of terminal used  on  such
       ports.

       The **-m **options maps from some set of conditions to a terminal type, that is, to tell **tset **“If
       I'm on this port at a particular speed, guess that I'm on that kind of terminal”.

       The argument to the **-m **option consists of an optional port type, an optional operator, an op‐
       tional  baud  rate specification, an optional colon (“:”) character and a terminal type.  The
       port type is a string (delimited by either the operator or the colon character).  The  opera‐
       tor  may be any combination of “>”, “<”, “@”, and “!”; “>” means greater than, “<” means less
       than, “@” means equal to and “!” inverts the sense of the test.  The baud rate  is  specified
       as  a number and is compared with the speed of the standard error output (which should be the
       control terminal).  The terminal type is a string.

       If the terminal type is not specified on the command line, the **-m **mappings are applied to the
       terminal type.  If the port type and baud rate match the mapping, the terminal type specified
       in the mapping replaces the current type.  If more than one mapping is specified,  the  first
       applicable mapping is used.

       For  example,  consider  the following mapping: **dialup>9600:vt100**.  The port type is dialup ,
       the operator is >, the baud rate specification is 9600, and the terminal type is vt100.   The
       result  of  this mapping is to specify that if the terminal type is **dialup**, and the baud rate
       is greater than 9600 baud, a terminal type of **vt100 **will be used.

       If no baud rate is specified, the terminal type will match any baud rate.  If no port type is
       specified, the terminal type will match any port  type.   For  example,  **-m  dialup:vt100  -m**
       **:?xterm  **will  cause  any  dialup  port,  regardless of baud rate, to match the terminal type
       vt100, and any non-dialup port type to match the terminal type ?xterm.  Note, because of  the
       leading  question mark, the user will be queried on a default port as to whether they are ac‐
       tually using an xterm terminal.

       No whitespace characters are permitted in the **-m **option argument.  Also,  to  avoid  problems
       with  meta-characters,  it  is  suggested that the entire **-m **option argument be placed within
       single quote characters, and that _csh_ users insert a backslash character (“\”) before any ex‐
       clamation marks (“!”).

## OPTIONS
       The options are as follows:

### -c   

### -e _
            Set the erase character to _ch_.

### -I   

### -i _
            Set the interrupt character to _ch_.

### -k _
            Set the line kill character to _ch_.

### -m _
            Specify a mapping from a port type to a terminal; see  subsection  “Terminal  Type  Map‐
            ping”.

### -Q   
            **tset **displays the values for control characters which differ from the  system's  default
            values.

### -q   
            ized in any way.  The option “-” by itself is equivalent but archaic.

### -r   

### -s   
            standard output; see subsection “Setting the Environment”.

### -V   

### -w   
            no effect, unless **setupterm **is not able to detect the window size.

       The arguments for the **-e**, **-i**, and **-k **options may either be entered as actual characters or by
       using the “hat” notation, i.e., control-h may be specified as “^H” or “^h”.

       If neither **-c **or **-w **is given, both options are assumed.

## ENVIRONMENT
       The **tset **command uses these environment variables:

       _SHELL_
            tells **tset **whether to initialize _TERM_ using [_sh_(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown) or [_csh_(1)](https://www.chedong.com/phpMan.php/man/csh/1/markdown) syntax.

       _TERM_ Denotes your terminal type.  Each terminal type is distinct, though many are similar.

       _TERMCAP_
            may denote the location of a termcap database.  If it is not an absolute pathname, e.g.,
            begins with a “/”, **tset **removes the variable from the environment before looking for the
            terminal description.

## FILES
       _/etc/ttys_
              system port name to terminal type mapping database (BSD versions only).

       _/etc/terminfo_
              compiled terminal description database directory

## PORTABILITY
       Neither IEEE Std 1003.1/The Open Group Base Specifications Issue 7 (POSIX.1-2008) nor  X/Open
       Curses Issue 7 documents **tset **or **reset**.

       The  AT&T  **tput  **utility (AIX, HP-UX, Solaris) incorporated the terminal-mode manipulation as
       well as termcap-based features such as resetting tabstops from **tset **in BSD (4.1c), presumably
       with the intention of making **tset **obsolete.  However, each of those  systems  still  provides
       **tset**.  In fact, the commonly-used **reset **utility is always an alias for **tset**.

       The  **tset  **utility  provides  backward compatibility with BSD environments; under most modern
       Unices, _/etc/inittab_ and [_getty_(8)](https://www.chedong.com/phpMan.php/man/getty/8/markdown) can set _TERM_ appropriately for each dial-up line, obviating
       what was **tset**'s most important use.  This implementation behaves like 4.4BSD **tset**, with a few
       exceptions we shall consider now.

       A few options are different because the _TERMCAP_ variable is no longer  supported  under  ter‐
       minfo-based _ncurses_:

       •   The **-S **option of BSD **tset **no longer works; it prints an error message to the standard er‐
           ror and dies.

       •   The **-s **option only sets _TERM_, not _TERMCAP_.

       There  was  an undocumented 4.4BSD feature that invoking **tset **via a link named “TSET” (or via
       any other name beginning with an upper-case letter) set the terminal to use upper-case  only.
       This feature has been omitted.

       The **-A**, **-E**, **-h**, **-u **and **-v **options were deleted from the **tset **utility in 4.4BSD.  None of them
       were documented in 4.3BSD and all are of limited utility at best.  The **-a**, **-d**, and **-p **options
       are  similarly not documented or useful, but were retained as they appear to be in widespread
       use.  It is strongly recommended that any usage of these three options be changed to use  the
### -m   -a -d -p 
       above.

       Very old systems, e.g., 3BSD, used a different terminal driver which was replaced in 4BSD  in
       the  early  1980s.  To accommodate these older systems, the 4BSD **tset **provided a **-n **option to
       specify that the new terminal driver should be used.  This implementation  does  not  provide
       that choice.

       It  is still permissible to specify the **-e**, **-i**, and **-k **options without arguments, although it
       is strongly recommended that such usage be fixed to explicitly specify the character.

       As of 4.4BSD, executing **tset **as **reset **no longer implies the **-Q **option.  Also, the interaction
       between the - option and the _terminal_ argument in some historic implementations of  **tset  **has
       been removed.

       The  **-c **and **-w **options are not found in earlier implementations.  However, a different window
       size-change feature was provided in 4.4BSD.

       •   In 4.4BSD, **tset **uses the window size from the termcap description to set the window  size
           if **tset **is not able to obtain the window size from the operating system.

       •   In _ncurses_, **tset **obtains the window size using **setupterm**, which may be from the operating
           system, the _LINES_ and _COLUMNS_ environment variables or the terminal description.

       Obtaining  the  window  size from the terminal description is common to both implementations,
       but considered obsolescent.  Its only practical use is  for  hardware  terminals.   Generally
       speaking,  a  window  size would be unset only if there were some problem obtaining the value
       from the operating system (and **setupterm **would still fail).  For that reason, the  _LINES_  and
       _COLUMNS_  environment  variables may be useful for working around window-size problems.  Those
       have the drawback that if the window is resized, those variables must be recomputed and reas‐
       signed.  To do this more easily, use the [**resize**(1)](https://www.chedong.com/phpMan.php/man/resize/1/markdown) program.

## HISTORY
       A **reset **command written by Kurt Shoens appeared in 1BSD (March 1978).  It set the  _erase_  and
       _kill_  characters  to  **^H  **(backspace) and **@ **respectively.  Mark Horton improved this **reset **in
       3BSD (October 1979), adding _intr_, _quit_, _start_/_stop_, and _eof_ characters as  well  as  changing
       the program to avoid modifying any user settings.  That version of **reset **did not use _termcap_.

       Eric  Allman  wrote  a  distinct  **tset **command for 1BSD, using a forerunner of _termcap_ called
       _ttycap_.  Allman's comments in the source code indicate that he began work  in  October  1977,
       continuing development over the next few years.  By late 1979, it had migrated to _termcap_ and
       handled  the  _TERMCAP_  variable.  Later comments indicate that **tset **was modified in September
       1980 to use logic copied from the 3BSD “reset” program when it was invoked  as  **reset**.   This
       version  appeared  in  4.1cBSD,  late in 1982.  Other developers such as Keith Bostic and Jim
       Bloom continued to modify **tset **until 4.4BSD was released in 1993.

       The _ncurses_ implementation was lightly adapted from the 4.4BSD sources to  use  the  _terminfo_
       API by Eric S. Raymond <<esr@snark.thyrsus.com>>.

## SEE ALSO
       [**csh**(1)](https://www.chedong.com/phpMan.php/man/csh/1/markdown), [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown), [**stty**(1)](https://www.chedong.com/phpMan.php/man/stty/1/markdown), [**terminfo**(3NCURSES)](https://www.chedong.com/phpMan.php/man/terminfo/3NCURSES/markdown), [**tty**(4)](https://www.chedong.com/phpMan.php/man/tty/4/markdown), [**terminfo**(5)](https://www.chedong.com/phpMan.php/man/terminfo/5/markdown), [**ttys**(4)](https://www.chedong.com/phpMan.php/man/ttys/4/markdown), [**environ**(7)](https://www.chedong.com/phpMan.php/man/environ/7/markdown)

ncurses 6.4                                  2023-12-23                                      [_tset_(1)](https://www.chedong.com/phpMan.php/man/tset/1/markdown)
