#Bash 的 setterm 命令
setterm [OPTION]...
功能
设置终端属性。
类型
可执行文件(/usr/bin/setterm),属于 util-linux。
参数
OPTION选项:--appcursorkeys on|off- 启用或禁用应用程序光标键模式--append console_number- 将输出追加到指定控制台--background 8-color|default- 设置背景颜色--blank[=0-60|force|poke]- 设置屏幕保护空白时间(分钟),force 强制立即空白,poke 重置计时--bfreq[=number]- 设置屏幕闪烁频率(Hz)--blength[=0-2000]- 设置屏幕闪烁长度(毫秒)--blink on|off- 启用或禁用闪烁文本--bold on|off- 启用或禁用粗体文本--clear[=all|rest]- 清屏,all 清除全部,rest 清除光标之后内容--clrtabs[=tab1 tab2 tab3 ...]- 清除指定制表位--cursor on|off- 显示或隐藏光标--default- 恢复终端默认设置--dump[=console_number]- 将控制台内容转储到文件--file filename- 指定 dump 文件名或输入文件--foreground 8-color|default- 设置前景颜色--half-bright on|off- 启用或禁用半亮显示--hbcolor 16-color- 设置半亮颜色--initialize- 初始化终端(清除屏幕、重置属性)--inversescreen on|off- 启用或禁用反显屏幕--linewrap on|off- 启用或禁用自动换行--msg on|off- 显示或隐藏终端信息消息--msglevel 0-8- 设置终端信息消息等级(0 最少,8 最多)--powerdown[=0-60]- 设置屏幕电源关闭时间(分钟)--powersave mode- 设置屏幕节能模式(如 on/off/standby)--regtabs[=1-160]- 设置标准制表位间隔--repeat on|off- 启用或禁用键盘重复功能--reset- 重置终端为默认状态--resize- 调整终端大小以匹配当前窗口--reverse on|off- 启用或禁用反色显示--store- 保存当前终端设置以便 later--restore--tabs[=tab1 tab2 tab3 ...]- 设置制表位--term terminal_name- 指定终端类型--ulcolor 16-color- 设置下划线文本颜色--underline on|off- 启用或禁用下划线--help- 显示帮助--version- 显示版本
#示例
$ setterm --clear # 清屏
$ setterm --foreground red # 设置前景色
$ setterm --background black # 设计背景色
$ setterm --cursor off # 不显示光标
$ setterm --bold on # 开启字体加粗
#推荐阅读
#手册
SETTERM(1) User Commands SETTERM(1)
NAME
setterm - set terminal attributes
SYNOPSIS
setterm [options]
DESCRIPTION
setterm writes to standard output a character string that will invoke
the specified terminal capabilities. Where possible terminfo is
consulted to find the string to use. Some options however (marked
"virtual consoles only" below) do not correspond to a terminfo(5)
capability. In this case, if the terminal type is "con" or "linux" the
string that invokes the specified capabilities on the PC Minix virtual
console driver is output. Options that are not implemented by the
terminal are ignored.
OPTIONS
For boolean options (on or off), the default is on.
Below, an 8-color can be black, red, green, yellow, blue, magenta,
cyan, or white.
A 16-color can be an 8-color, or grey, or bright followed by red,
green, yellow, blue, magenta, cyan, or white.
The various color options may be set independently, at least on virtual
consoles, though the results of setting multiple modes (for example,
--underline and --half-bright) are hardware-dependent.
The optional arguments are recommended with '=' (equals sign) and not
space between the option and the argument. For example
--option=argument. setterm can interpret the next non-option argument
as an optional argument too.
--appcursorkeys on|off
Sets Cursor Key Application Mode on or off. When on, ESC O A, ESC O
B, etc. will be sent for the cursor keys instead of ESC [ A, ESC [
B, etc. See the vi and Cursor-Keys section of the
Text-Terminal-HOWTO for how this can cause problems for vi users.
Virtual consoles only.
--append console_number
Like --dump, but appends to the snapshot file instead of
overwriting it. Only works if no --dump options are given.
--background 8-color|default
Sets the background text color.
--blank[=0-60|force|poke]
Sets the interval of inactivity, in minutes, after which the screen
will be automatically blanked (using APM if available). Without an
argument, it gets the blank status (returns which vt was blanked,
or zero for an unblanked vt). Virtual consoles only.
The force argument keeps the screen blank even if a key is pressed.
The poke argument unblanks the screen.
--bfreq[=number]
Sets the bell frequency in Hertz. Without an argument, it defaults
to 0. Virtual consoles only.
--blength[=0-2000]
Sets the bell duration in milliseconds. Without an argument, it
defaults to 0. Virtual consoles only.
--blink on|off
Turns blink mode on or off. Except on a virtual console, --blink
off turns off all attributes (bold, half-brightness, blink,
reverse).
--bold on|off
urns bold (extra bright) mode on or off. Except on a virtual
console, --bold off turns off all attributes (bold,
half-brightness, blink, reverse).
--clear[=all|rest]
Without an argument or with the argument all, the entire screen is
cleared and the cursor is set to the home position, just like
clear(1) does. With the argument rest, the screen is cleared from
the current cursor position to the end.
--clrtabs[=tab1 tab2 tab3 ...]
Clears tab stops from the given horizontal cursor positions, in the
range 1-160. Without arguments, it clears all tab stops. Virtual
consoles only.
--cursor on|off
Turns the terminal’s cursor on or off.
--default
Sets the terminal’s rendering options to the default values.
--dump[=console_number]
Writes a snapshot of the virtual console with the given number to
the file specified with the --file option, overwriting its
contents; the default is screen.dump. Without an argument, it dumps
the current virtual console. This overrides --append.
--file filename
Sets the snapshot file name for any --dump or --append options on
the same command line. If this option is not present, the default
is screen.dump in the current directory. A path name that exceeds
the system maximum will be truncated, see PATH_MAX from
linux/limits.h for the value.
--foreground 8-color|default
Sets the foreground text color.
--half-bright on|off
Turns dim (half-brightness) mode on or off. Except on a virtual
console, --half-bright off turns off all attributes (bold,
half-brightness, blink, reverse).
--hbcolor 16-color
Sets the color for half-bright characters.
--initialize
Displays the terminal initialization string, which typically sets
the terminal’s rendering options, and other attributes to the
default values.
--inversescreen on|off
Swaps foreground and background colors for the whole screen.
--linewrap on|off
Makes the terminal continue on a new line when a line is full.
--msg on|off
Enables or disables the sending of kernel printk() messages to the
console. Virtual consoles only.
--msglevel 0-8
Sets the console logging level for kernel printk() messages. All
messages strictly more important than this will be printed, so a
logging level of 0 has the same effect as --msg on and a logging
level of 8 will print all kernel messages. klogd(8) may be a more
convenient interface to the logging of kernel messages.
Virtual consoles only.
--powerdown[=0-60]
Sets the VESA powerdown interval in minutes. Without an argument,
it defaults to 0 (disable powerdown). If the console is blanked or
the monitor is in suspend mode, then the monitor will go into vsync
suspend mode or powerdown mode respectively after this period of
time has elapsed.
--powersave mode
Valid values for mode are:
vsync|on
Puts the monitor into VESA vsync suspend mode.
hsync
Puts the monitor into VESA hsync suspend mode.
powerdown
Puts the monitor into VESA powerdown mode.
off
Turns monitor VESA powersaving features.
--regtabs[=1-160]
Clears all tab stops, then sets a regular tab stop pattern, with
one tab every specified number of positions. Without an argument,
it defaults to 8. Virtual consoles only.
--repeat on|off
Turns keyboard repeat on or off. Virtual consoles only.
--reset
Displays the terminal reset string, which typically resets the
terminal to its power-on state.
--resize
Reset terminal size by assessing maximum row and column. This is
useful when actual geometry and kernel terminal driver are not in
sync. Most notable use case is with serial consoles, that do not
use ioctl(2) but just byte streams and breaks.
--reverse on|off
Turns reverse video mode on or off. Except on a virtual console,
--reverse off turns off all attributes (bold, half-brightness,
blink, reverse).
--store
Stores the terminal’s current rendering options (foreground and
background colors) as the values to be used at reset-to-default.
Virtual consoles only.
--tabs[=tab1 tab2 tab3 ...]
Sets tab stops at the given horizontal cursor positions, in the
range 1-160. Without arguments, it shows the current tab stop
settings.
--term terminal_name
Overrides the TERM environment variable.
--ulcolor 16-color
Sets the color for underlined characters. Virtual consoles only.
--underline on|off
Turns underline mode on or off.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
COMPATIBILITY
Since version 2.25 setterm has support for long options with two
hyphens, for example --help, beside the historical long options with a
single hyphen, for example -help. In scripts it is better to use the
backward-compatible single hyphen rather than the double hyphen.
Currently there are no plans nor good reasons to discontinue
single-hyphen compatibility.
BUGS
Differences between the Minix and Linux versions are not documented.
SEE ALSO
stty(1), tput(1), tty(4), terminfo(5)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The setterm command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-21 SETTERM(1)