tput
Query and set terminal capabilities
TLDR
Set bold text
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 modedim
Enable half-bright/dim modesmul / rmul
Start/end underline moderev
Enable reverse video modeblink
Enable blinking textsmso / rmso
Start/end standout modesgr0
Reset all attributes to defaultsetaf n
Set foreground color (0-7 or 0-255)setab n
Set background colorclear
Clear screen and move cursor homecup row col
Move cursor to positioncols
Print number of columnslines
Print number of linessc / rc
Save/restore cursor positioncivis / 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.
