The Computer Oracle

Get display resolution from the command line for Linux Desktop

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping

--

Chapters
00:00 Get Display Resolution From The Command Line For Linux Desktop
00:22 Accepted Answer Score 43
00:37 Answer 2 Score 5
00:57 Answer 3 Score 13
01:14 Answer 4 Score 10
01:54 Thank you

--

Full question
https://superuser.com/questions/418699/g...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #xorg #displaysettings

#avk47



ACCEPTED ANSWER

Score 43


Use the command xrandr. Without any argument it displays the available resolutions and the current one (with an asterisk), for instance:

$ xrandr | fgrep '*'



ANSWER 2

Score 13


Alternative solution: xdpyinfo | grep dimensions. xdpyinfo is older than xrandr, so might be more portable if you happen to use a very old distribution or some different X server.




ANSWER 3

Score 10


You can get the horizontal and vertical resolutions using the following command:

xdpyinfo | grep dimensions | awk '{print $2}' | awk -Fx '{print $1, $2}'

or, in more compact form (as suggested by Peter.O in this comment):

xdpyinfo | awk -F'[ x]+' '/dimensions:/{print $3, $4}' 

For exmaple, on a 1600x900 display this will produce the following output:

1600 900

You can then place the values into separate variables using the command:

read RES_X RES_Y <<<$(xdpyinfo | awk -F'[ x]+' '/dimensions:/{print $3, $4}')

Display the values of the above variables using the command:

echo $RES_X, $RES_Y

On a 1600x900 display, the output is:

1600, 900



ANSWER 4

Score 5


I should have looked a little harder before posting. xrandr will echo the current display settings, if not given any other arguments.

By default, this will dump all possible display settings, this can be filtered as follows:

xrandr | egrep '^[^ ]|[0-9]\*\+'