15

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?

Stefan
  • 24,830
  • 40
  • 98
  • 126

3 Answers3

17

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
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
  • 1
    If running `xrandr`over 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
  • In my case, when running the command across a SSH PuTTY session to a Raspberry PI, I had to use: xrandr --display :0.0 – nwsmith Aug 11 '23 at 12:41
7

From my personal shell library:

get_screen_size()
{
    xdpyinfo | awk '/dimensions:/ { print $2; exit }'
}
camh
  • 38,261
  • 8
  • 74
  • 62
3

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}'

1366x768
Serge Stroobandt
  • 2,314
  • 3
  • 32
  • 36