← 返回命令列表

Linux command

tput 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Set bold text

tput bold

Set foreground color

tput setaf [2]

Set background color

tput setab [4]

Reset all attributes

tput sgr0

Clear the screen

tput clear

Get terminal width

tput cols

Get terminal height

tput lines

Move cursor

tput cup [5] [10]

说明

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.

参数

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

FAQ

What is the tput command used for?

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.

How do I run a basic tput example?

Run `tput bold` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -T _type_ do in tput?

Specify terminal type; defaults to $TERM environment variable