I would like to run a command like get-screen-resolution during a X session to get a '800x480' output. ( or whatever the actual screen size is ).

Is there something available for this? Currently I take a screenshot and measure the resulting *.jpg's width & height attributes.

Also, how do I set the screensize during a X session from the command-line?


You can use xrandr to do both

Get resolution

$ xrandr
Screen 0: minimum 320 x 240, current 1920 x 1080, maximum 1920 x 1080
default connected 1920x1080+0+0 0mm x 0mm

Set resolution

$ xrandr --output default --mode 1280x1024
| improve this answer | |
  • If running xrandrover SSH, it is important to explicitly specify the display either by adding the parameter --display 0 to your example, or by first setting the environment variable export DISPLAY=0 before running your example. This is because the display cannot automatically be detected over SSH connections. – Jonathan Komar Oct 29 '17 at 17:34

From my personal shell library:

    xdpyinfo | awk '/dimensions:/ { print $2; exit }'
| improve this answer | |
  • 2
    In a multi-monitor setup this will show the dimensions of the bounding box which contains all monitors. – Paused until further notice. May 17 '19 at 20:26

Clean xrandr output for imagemagick use

The following line takes the output of xrandr and cleans it with awk for use with imagemagick:

$ xrandr |awk '$0 ~ "*" {print $1}'

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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