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

How do I find out my screen resolution from a shell script?

share|improve this question
up vote 38 down vote accepted
xdpyinfo  | grep dimensions
share|improve this answer

xdpyinfo | grep dimensions will give you the total resolution, if you have multiple monitors it will be the sum of all of them. xrandr --current will give you the resolution for each monitor.

I use this snippet to find the maximum possible resolution for rDesktop without going to full screen:

Xaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)

Yaxis=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)

Output:

Xaxis = 1280
Yaxis = 1024

Minus windows decoration (more or less):

MaxRes=$(($Xaxis-5))"x"$(($Yaxis-25))

Output:

MaxRes = 1275x999

Which is the max resolution for rDesktop without going full screen.

End command:

rdesktop -u $User -P -z -5 -g $MaxRes $Host &

It works fine so far but I haven't tested thoroughly though.

Another example is for screencast with avconv:

avconv -f x11grab -r 15 -s `xrandr --current | grep  '*' | uniq | awk '{print $1}'` -i :0.0 -c:v libx264 ./output.mp4
share|improve this answer
    
it says> xdpyinfo: Unable to open display "". – To Kra Dec 14 '15 at 9:27
    
How do you find out the available modes to change to? – CMCDragonkai Feb 8 at 6:32

You could use the xrandr -q command. From that you can create a shell script if needed.

For more information on the command go here or type man xrandr

share|improve this answer

xdpyinfo will do it, with some parsing. It gives a lot of info which you'll then have to dig the screen number, and dimensions from

share|improve this answer
#############################################
## I use this with a Video Recording Program.
#  window size --root option - information on the screen's root window
echo $(xwininfo -root | grep 'geometry' | awk '{print $2;}')
# output(s): 1024x768+0+0
#            height x width + x + y positions.
######################
## Reference Manual ##
man xwininfo
share|improve this answer

You must log in to answer this question.

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