tset Command in Linux



The tset command in Linux initializes the terminal. It is used to set up the terminal type and initialize terminal settings, such as special characters and modes. It retrieves the terminal mode settings by testing them in order: standard error, standard output, standard input, and finally /dev/tty. This is especially useful in scripts or login sessions to ensure the terminal behaves correctly.

Table of Contents

Here is a comprehensive guide to the options available with the tset command in Linux −

Syntax of tset Command

The syntax of the tset command in Linux is as follows −

tset [options] [terminal]

In the above syntax, the [options] field is used to specify flags that modify how tset behaves. The [terminal] argument is an optional argument used to manually specify the terminal type.

Options of tset Command

The options for the Linux tset command are listed below −

Option Description
-c Set control characters and modes.
-e ch Set the erase character to ch.
-I Do not send terminal or tab initialization strings.
-i ch Set the interrupt character to ch.
-k ch Set the line kill character to ch.
-m mapping Map a port type to a terminal.
-Q Suppress display of erase, interrupt, and line kill characters.
-q Print the terminal type without initializing it.
-r Print terminal type to standard error.
-s Print shell commands to set TERM.
-V Display the ncurses version used and exit.
-w Resize the window based on setupterm detection.

Using tset Command in Linux

This section explores how to use the tset command in Linux with examples −

Initializing a Terminal

To initialize a terminal using the current TERM environment variable, use the tset command without any options −

tset

Setting Terminal Type and Modes

To set the terminal type manually and configure the terminal settings, use the tset command followed by the terminal type −

tset vt100

Note that the tset command by itself does not change $TERM, it just sets terminal modes and optionally prints the terminal type. To update $TERM, it must be done using the following command −

export TERM=vt100
tset Command in Linux1

Displaying Shell Command to Set the Terminal Type

To display the shell command to set the terminal type or $TERM, use the -s option −

tset -s
tset Command in Linux2

Displaying Terminal Type to Standard Error

To display the terminal type to standard error, use the -r option −

tset -r
tset Command in Linux3

Setting the Erase Character

The erase character is a special control character used in the terminal to delete the last typed character; essentially, it acts like a backspace. To set the erase character, use the -e option −

tset -e '^H'

To view the current erase character, use the following command −

stty -a | grep erase
tset Command in Linux4

Setting the Interrupt Character

To set the interrupt character, use the -i option −

tset -i '^C'

Pressing this key will stop a running foreground process.

To view the current interrupt character, use the following command −

stty -a | grep intr

Setting the Line Kill Character

To set the line kill character, use the -k option −

tset -k '^K'

Displaying Terminal Type without Initializing

To display the terminal type without initializing, use the -q option −

tset -q
tset Command in Linux5

Adjusting the Terminal Window

The -w option adjusts the terminal's size based on the dimensions detected by the setupterm function −

tset -w
tset Command in Linux6

The above command adjusts the terminal size according to detected dimensions.

Conclusion

The tset command in Linux helps set up and initialize terminal settings to ensure proper behavior, especially in scripts or login sessions. It allows configuration of special control characters like erase, interrupt, and line kill, and offers various options for customizing terminal initialization. The tset command can also detect and display terminal types, map terminal settings, and resize terminal windows.

Advertisements