Get screen width and hight with tput

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Fixing the display with resetHomeMoving the cursor with tput →

Type the following command at a shell prompt to get screen width:

tput cols

Sample outputs:

157

You can get and export screen width with the shell variable called COLUMNS (used by the select builtin command to determine the terminal width when printing selection lists):

COLUMNS=$(tput cols) 
export COLUMNS

To get height, enter:

tput lines

Sample outputs:

56
← Fixing the display with resetHomeMoving the cursor with tput →