Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to know my current xterms' window sizes. I'm using Cygwin. Is there a command to just print that to the prompt?

share|improve this question
up vote 3 down vote accepted

If it's an actual xterm, the following should work (tested on a PuTTY session, since I don't have Cygwin installed at the moment):

stty -a | sed 's/;/\n/g' | grep rows | awk '{print $2}'

In my case, that returned 24. Similarly,

stty -a | sed 's/;/\n/g' | grep columns | awk '{print $2}'

returned 80.

All the commands involved should be standard in Cygwin or any UNIX-like system. I'd be very surprised if they didn't work equally well in a Cygwin console prompt.

share|improve this answer
    
thank you this works great! – Robb Jul 6 '11 at 13:45

Gives you the size in characters:

 echo $COLUMNS " " $LINES

Whether it works in cygwin? You tell us!

share|improve this answer

Install the ncurses package, then execute

tput cols; tput lines
share|improve this answer

If you want to avoid using a search and replace regular expression and the sed command...

Note: Run stty -a by itself to determine the position of the rows value.

stty -a | grep rows | tr -d ';' | awk {'print $5'}

In my case (an xterm in Open Solaris running Gnome), this returned 24.


If you want to avoid using a search and replace regular expression, sed, and awk ...

stty -a | grep rows | tr -d ';' | cut -d ' ' -f 5

Again, 24.


If you want to avoid using a search and replace regular expression, sed, grep, and awk ...

stty -a | head -n 1 | tr -d ';' | cut -d ' ' -f 5

Again, 24.

You can find the width of your terminal simply by altering one of these commands to point towards the columns value of stty -a.


If you do not like using stty -a ...

resize | grep LINES | tr -d ';' | cut -d = -f 2

and

resize | grep COLUMNS | tr -d ';' | cut -d = -f 2
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .