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?


3 Answers 3


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
  • 1
    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. Oct 29, 2017 at 17:34

From my personal shell library:

    xdpyinfo | awk '/dimensions:/ { print $2; exit }'
  • 3
    In a multi-monitor setup this will show the dimensions of the bounding box which contains all monitors. May 17, 2019 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}'

  • Looks like you need gawk; mawk doesn't recognize that syntax Nov 10, 2021 at 21:17
  • xrandr | grep '*' | awk '{print $1}' should work with any awk Nov 10, 2021 at 21:32

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.