On Unix-like operating systems, the tput command initializes a terminal or queries the terminfo database.

This page covers the Linux version of tput.

Description

The tput utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell, to initialize or reset the terminal, or return the long name of the requested terminal type. The result depends upon the capability’s type:

  • Description
  • Syntax
  • Exit codes
  • Diagnostics
  • Examples
  • Related commands
  • Linux commands help

Before using a value returned on the standard output, the application should test the exit code (for example, $?; see sh for details) to be sure it is 0. (See the exit codes and diagnostics sections.) For a complete list of capabilities and the capname associated with each, see the manual for terminfo.

Syntax

tput [-Ttype] capname [params … ]

tput [-Ttype] init

tput [-Ttype] reset

tput [-Ttype] longname

tput -S «

tput -V

Options

If tput is invoked by a link named reset, this has the same effect as tput reset. See tset for comparison, which has similar behavior.

  • If present, the terminal’s initialization strings will be output as detailed in the terminfo section on Tabs and Initialization,Any delays (e.g., newline) specified in the entry will be set in the tty driver,Tabs expansion will be turned on or off according to the specification in the entry, andIf tabs are not expanded, standard tabs will be set, every 8 spaces.

Exit codes

If the -S option is used, tput checks for errors from each line, and if any errors are found, sets the exit code to 4 plus the number of lines with errors. If no errors are found, the exit code is 0. No indication of which line failed can be given so exit code 1 never appears. Exit codes 2, 3, and 4 retain their usual interpretation. If the -S option is not used, the exit code depends on the type of capname:

Any other exit code indicates an error, as listed in the diagnostics section.

Diagnostics

tput prints the following error messages and sets the corresponding exit codes:

Files

Examples

tput init

Initialize the terminal according to the type of terminal in the environment variable TERM. This command should be included in the .profile file after the environment variable TERM has been exported.

tput -T5620 reset

Reset an AT&T 5620 terminal, overriding the type of terminal in the environment variable TERM.

tput cup 0 0

Send the sequence to move the cursor to row 0, column 0 (the upper left corner of the screen, usually known as the “home” cursor position).

tput clear

Echo the clear-screen sequence for the current terminal.

tput cols

Print the number of columns for the current terminal.

tput -T450 cols

Print the number of columns for the 450 terminal.

bold=tput smso offbold=tput rmso

Set the shell variables bold, to begin stand-out mode sequence, and offbold, to end standout mode sequence, for the current terminal. This command might be followed by a prompt: echo “${bold}Please type in your name: ${offbold}\c”.

tput hc

Set exit code to indicate if the current terminal is a hard copy terminal.

tput cup 23 4

Send the sequence to move the cursor to row 23, column 4.

tput cup

Send the terminfo string for cursor-movement, with no parameters substituted.

tput longname

Print the long name from the terminfo database for the type of terminal specified in the environment variable TERM.

clear — Clear the screen.stty — Set options for your terminal display.tabs — Set tab stops on a terminal.