LinuxCommandLibrary

tput

Query and set terminal capabilities

TLDR

Set bold text

$ tput bold
copy
Set foreground color (0-7: black, red, green, yellow, blue, magenta, cyan, white)
$ tput setaf [2]
copy
Set background color
$ tput setab [4]
copy
Reset all attributes to default
$ tput sgr0
copy
Clear the screen
$ tput clear
copy
Get terminal width in columns
$ tput cols
copy
Get terminal height in lines
$ tput lines
copy
Move cursor to row and column
$ tput cup [5] [10]
copy

SYNOPSIS

tput [-T type] capname [parameters...]

DESCRIPTION

tput queries the terminfo database to output terminal-dependent capabilities. It provides a portable way to control terminal features like colors, cursor positioning, and text attributes without hardcoding escape sequences.
The command uses the $TERM environment variable to determine the terminal type and looks up the appropriate escape sequences. This makes scripts portable across different terminal emulators.
Color numbers 0-7 represent basic colors: black (0), red (1), green (2), yellow (3), blue (4), magenta (5), cyan (6), white (7). Extended color terminals support 256 colors (0-255).
Common usage in scripts combines capabilities: $(tput bold)$(tput setaf 1)Error$(tput sgr0) prints "Error" in bold red, then resets.

PARAMETERS

-T type

Specify terminal type; defaults to $TERM environment variable
-S
Read capabilities from stdin, allowing multiple operations
-V
Print ncurses version and exit

COMMON CAPABILITIES

bold

Enable bold mode
dim
Enable half-bright/dim mode
smul / rmul
Start/end underline mode
rev
Enable reverse video mode
blink
Enable blinking text
smso / rmso
Start/end standout mode
sgr0
Reset all attributes to default
setaf n
Set foreground color (0-7 or 0-255)
setab n
Set background color
clear
Clear screen and move cursor home
cup row col
Move cursor to position
cols
Print number of columns
lines
Print number of lines
sc / rc
Save/restore cursor position
civis / cnorm
Hide/show cursor

CAVEATS

Capabilities vary by terminal type; not all terminals support all features. Always reset attributes with sgr0 after use to avoid affecting subsequent output. The -T option should match the actual terminal for correct behavior.

HISTORY

tput was introduced in System V Unix in the early 1980s as part of the terminfo system, which replaced the older termcap. The ncurses implementation provides the tput command on most Linux systems today. It was designed to abstract terminal-specific escape codes behind a consistent interface.

SEE ALSO

terminfo(5), infocmp(1), tic(1), clear(1), reset(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community