Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

4 Answers 4

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
    
This works in Cygwin's xterm :) –  Matthew Read Jul 6 '11 at 1:06
    
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
    
This doesn't work in Cygwin's xterm :( –  Matthew Read Jul 6 '11 at 1:05

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.