commandLinux tput Command Usage Guide(linuxtput)

Linux tput Command is an inbuilt command line utility that is used to write terminal control characters, providing a way to manipulate terminals from within shell scripts. tput prints a message to standard error if it encounters an unrecognized command.

The Linux tput command is often used when writing shell scripts involving a command line terminal. It can be used to set terminal attributes and modes, colorize terminal text, display strings, move the cursor, erase lines, control the width of the lines, control cursor visibility within the terminal, control the visual bell, control the visibility of the cursor, and many more.

To use tput, the first parameter must be a command from the list below. There are many command choices similar to escape sequences used in ANSI-compatible terminals. For example, tput setaf and tput setab are two commands used to change the foreground and background color respectively.

The following is a list of common tput commands:

• setaf: set the terminal’s foreground color to a specified color.

• setab: set the terminal’s background color to a specified color.

• rev: reverse the foreground and background colors.

• smul: enable underlining.

• rmul: disable underlining.

• bold: enable bold text.

• dim: enable dim text.

• sgr0: reset all attributes.

• tsl: set the number of lines from the terminal.

• sucl: set the number of columns from the terminal.

• cnorm: normalize the cursor.

• civis: hide the cursor.

• cvvis: show the cursor.

• smso: enable the cursor.

• rmso: disable the cursor.

• sgr: set a combination of attributes at once.

• smacs: enter alternate character set mode.

• rmacs: exit alternate character set mode.

The following is a simple script that demonstrates the usage of tput to change the foreground and background color of a terminal:

#!/bin/bash

echo “Setting terminal to bright yellow text on red background…”

tput setaf 3

tput setab 1

echo “It’s alive!”

tput sgr0

This simple script will output a string with the specified text and background colors. When the command tput sgr0 is reached, the terminal’s attributes are reset to their defaults.

To make use of the Linux tput command in your own scripts, make sure to read up on all of the available commands and use cases along with the syntax for using each command. Doing so will ensure that your scripts are properly formatted and will run as smoothly as possible.

In conclusion, the Linux tput command is a powerful tool that can be used to manipulate the display mode and attributes of a terminal within a script. It provides numerous useful commands such as setting the text color, background color, and many more. With some practice and knowledge of the available tput commands, scripts can easily be written to control the display mode of terminals.


数据运维技术 » commandLinux tput Command Usage Guide(linuxtput)