System
tput
Query and modify terminal capabilities.
terminalterminfodisplaycursorcolor
Additional Notes
tput uses the terminal capability database (terminfo) to query terminal characteristics and control terminal output. It can move the cursor, change text attributes (bold, underline, reverse video, colors), clear the screen, and query terminal features like the number of columns and rows.
It is commonly used in shell scripts to produce formatted and colored output without hard-coding escape sequences. The behavior depends on the $TERM environment variable. If the terminal type is not recognized, tput may produce incorrect or empty output.
Syntax
tput [options] capability [parameters]
Capabilities
clear: Clear the screen.cols: Number of columns in the terminal.lines: Number of lines in the terminal.bold: Start bold text.sgr0: Reset all attributes.setaf N: Set foreground color (0-7 or 0-255).setab N: Set background color.rev: Start reverse video.smul: Start underline mode.rmul: End underline mode.cup Y X: Move cursor to row Y, column X (0-based).bel: Ring the terminal bell.sc: Save cursor position.rc: Restore cursor position.civis: Hide cursor.cnorm: Show normal cursor.
Parameters
options: Flags that change howtputbehaves.target: Optional file, device, interface, user, service, or command target when the command supports one.
Common Options
-T type: Use the terminfo entry fortypeinstead of the current$TERM.-S: Read capabilities from stdin for batch processing.-x: Allow extended capabilities that are not part of the standard terminfo.
Examples
tput cols
Print the number of columns in the terminal.
tput cup 10 20
Move the cursor to row 10, column 20.
echo "$(tput bold)Important$(tput sgr0) message"
Print bold text and reset attributes.
echo "$(tput setaf 2)Green text$(tput sgr0)"
Print green text.
tput clear
Clear the terminal screen.
Practical Notes
tputdepends on the terminfo database. If a terminal type is missing, install thencurses-termpackage.- Use
sgr0to reset all text attributes;rmsoorrmulreset only individual attributes. - For 256-color terminals, use colors 0-255 with
setaf/setab. - Always reset attributes after applying them, or the terminal state may bleed into subsequent output.
- The
infocmpcommand can show the full terminfo entry for a terminal type.