Current window size of an xterm window

0

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?

Robb

Posted 2011-07-06T00:25:18.083

Reputation: 167

Answers

4

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.

Mike Renfro

Posted 2011-07-06T00:25:18.083

Reputation: 1 242

0

Gives you the size in characters:

 echo $COLUMNS " " $LINES

Whether it works in cygwin? You tell us!

user unknown

Posted 2011-07-06T00:25:18.083

Reputation: 1 623

0

Install the ncurses package, then execute

tput cols; tput lines

garyjohn

Posted 2011-07-06T00:25:18.083

Reputation: 29 085

0

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

Anthony Rutledge

Posted 2011-07-06T00:25:18.083

Reputation: 111