Skip to content

tput MacOS Command Guide

The MacOS tput command is a powerful tool for controlling terminal output and cursor positioning. It allows users to manipulate various terminal capabilities such as colors, cursor movement, and text attributes. By using tput, users can enhance the visual appearance of their scripts and create dynamic and interactive terminal interfaces. With its easy-to-use syntax and wide range of functionality, tput is an essential command for any MacOS user looking to streamline their terminal workflow.

tput Syntax:

Terminal window
tput [option] [parameter]

Options:

OptionDescription
clearClear the screen
cupMove cursor to specified position
boldSet bold mode
dimSet dim mode
smulStart underline mode
rmulEnd underline mode
revSet reverse video mode

Parameters:

ParameterDescription
sgr0Turn off all attributes (ANSI escape)
setafSet foreground color (ANSI escape)
setabSet background color (ANSI escape)
blinkSet blink mode
civisMake cursor invisible

tput Command Samples:

Change Text Color to Red

Terminal window
tput setaf 1

This command changes the text color to red.

Change Background Color to Green

Terminal window
tput setab 2

This command changes the background color to green.

Reset Text Color to Default

Terminal window
tput sgr0

This command resets the text color to the default setting.

Hide Cursor

Terminal window
tput civis

This command hides the cursor.

Show Cursor

Terminal window
tput cnorm

This command shows the cursor.

Move Cursor to Specific Position

Terminal window
tput cup 5 10

The command moves the cursor to the 5th row and 10th column on the terminal screen.

Get Terminal Size

Terminal window
tput cols
tput lines

These commands display the number of columns and lines in the terminal window, respectively.

How do I use tput in MacOS?

To use the tput command in MacOS, execute the following command:

Terminal window
tput --option <value>

What is the purpose of tput in MacOS?

The tput command in MacOS is used to query and set terminal capabilities such as cursor movement, text coloring, and terminal modes.

How do I change the text color using tput in MacOS?

To change the text color using tput in MacOS, you can use the following command to set the text color to red:

Terminal window
tput setaf 1

Can tput in MacOS be used to move the cursor position?

Yes, tput in MacOS can be used to move the cursor position. For example, the following command moves the cursor to the 10th column and 5th row:

Terminal window
tput cup 5 10

How can I clear the screen using tput in MacOS?

To clear the screen using tput in MacOS, you can use the following command:

Terminal window
tput clear

Is it possible to set bold text using tput in MacOS?

Yes, you can set bold text using tput in MacOS. The following command sets the text to bold:

Terminal window
tput bold

Applications of the tput command

  • Clear the screen
  • Move the cursor to a specific position
  • Get the number of columns on the current terminal
  • Change text attributes like bold, underline, etc.
  • Change text colors
  • Save the current cursor position
  • Restore the saved cursor position
  • Hide or show the cursor