Linux tput command

The tput command in Linux is used to manipulate terminal settings, such as cursor movement, text formatting, and color output. It provides a way to interact with the terminal’s capabilities in a standardized and portable manner.

Here are some examples of how you can use the tput command:

  1. Changing text color:
tput setaf 2     # Set the foreground color to green
echo "Hello, World!"
tput sgr0        # Reset text formatting

2. Changing background color:

tput setab 4     # Set the background color to blue
echo "Hello, World!"
tput sgr0        # Reset text formatting

3. Moving the cursor:

tput cup 5 10    # Move the cursor to row 5, column 10
echo "Hello!"

4. Clearing the screen:

tput clear       # Clear the entire terminal screen

5. Getting terminal size:

lines=$(tput lines)     # Get the number of lines in the terminal
cols=$(tput cols)       # Get the number of columns in the terminal
echo "Terminal size: $lines lines x $cols columns"

These are just a few examples of what you can do with the tput command. It provides many more capabilities for controlling terminal output. You can refer to the tput manual page (man tput) for more details and a comprehensive list of available options and capabilities.

Leave a Comment

Your email address will not be published. Required fields are marked *