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.

Terminal window
tput [option] [parameter]
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
ParameterDescription
sgr0Turn off all attributes (ANSI escape)
setafSet foreground color (ANSI escape)
setabSet background color (ANSI escape)
blinkSet blink mode
civisMake cursor invisible
Terminal window
tput setaf 1

This command changes the text color to red.

Terminal window
tput setab 2

This command changes the background color to green.

Terminal window
tput sgr0

This command resets the text color to the default setting.

Terminal window
tput civis

This command hides the cursor.

Terminal window
tput cnorm

This command shows the cursor.

Terminal window
tput cup 5 10

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

Terminal window
tput cols
tput lines

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

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

Terminal window
tput --option <value>

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?

Section titled “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?

Section titled “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?

Section titled “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?

Section titled “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
  • 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