home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Use tputs To Get The Number Of Columns And Lines/Rows Count In A Terminal Window On A Mac

July 2023

TL;DR - Columns

Code
tputs cols

-- results

55

TL;DR - Lines/Rows

Code
tputs lines

-- results

38
  • I generally use tputs when I need to figure out the number of columns or lines/rows a terminal window has

  • This probably works on lots of linux machines too. ymmv are on windows

  • I'm not sure if tputs is installed by default or if it got installed by homebrew. I don't remember installing it, but if you don't have it you may have to do that work

  • `bash`, `zsh`, and some other shells also set ENV vars that can be used to pull the numbers (link below)

═══ § ═══

Footnotes And References