59

What is the Ubuntu linux command to find laptop monitor size? I want to know in inches if possible.

Thanks

Jacob Vlijm
  • 83,767
user111
  • 661
  • 1
  • 7
  • 9
  • Hi user111, please see this: http://meta.askubuntu.com/q/15051/72216. Could you at least provide some feedback? – Jacob Vlijm Feb 23 '16 at 20:51

5 Answers5

69

Another option, using xrandr, is the command:

xrandr | grep ' connected'

Output:

DVI-I-1 connected primary 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
VGA-1 connected 1280x1024+1680+0 (normal left inverted right x axis y axis) 376mm x 301mm

(mind the space before connected, else disconnected will be included)

Important differences between xdpyinfo and xrandr

  • While xrandr lists screens separately (in case of multiple monitors), xdpyinfo outputs one single set of dimensions for all screens together ("desktop size" instead of screen size)
  • As noticed by @agold there is (quite) a difference between the two, which seems too big to be a simple rounding difference:

    xrandr: 473mm x 296mm
    xdpyinfo: 445x278
    

It seems related to a bug in xdpyinfo. See also here.

If you'd insist on inches

Use the small script below; it outputs the size of your screen(s) in inches; width / height / diagonal (inches)

#!/usr/bin/env python3
import subprocess
# change the round factor if you like
r = 1

screens = [l.split()[-3:] for l in subprocess.check_output(
    ["xrandr"]).decode("utf-8").strip().splitlines() if " connected" in l]

for s in screens:
    w = float(s[0].replace("mm", "")); h = float(s[2].replace("mm", "")); d = ((w**2)+(h**2))**(0.5)
    print([round(n/25.4, r) for n in [w, h, d]])

To use it:

Copy the script into an empty file, save it as get_dimensions.py, run it by the command:

python3 /path/to/get_dimensions.py

Output on my two screens:

width - height - diagonal (inches)

[18.6, 11.7, 22.0]
[14.8, 11.9, 19.0]



Edit

Fancy version of the same script (with a few improvements and a nicer output), looking like:

Screen  width   height  diagonal
--------------------------------
DVI-I-1 18.6    11.7    22.0
VGA-1   14.8    11.9    19.0

The script:

#!/usr/bin/env python3
import subprocess
# change the round factor if you like
r = 1

screens = [l.split() for l in subprocess.check_output(
    ["xrandr"]).decode("utf-8").strip().splitlines() if " connected" in l]

scr_data = []
for s in screens:
    try:
        scr_data.append((
            s[0],
            float(s[-3].replace("mm", "")),
            float(s[-1].replace("mm", ""))
            ))
    except ValueError:
        pass

print(("\t").join(["Screen", "width", "height", "diagonal\n"+32*"-"]))
for s in scr_data:
    scr = s[0]; w = s[1]/25.4; h = s[2]/25.4; d = ((w**2)+(h**2))**(0.5)
    print(("\t").join([scr]+[str(round(n, 1)) for n in [w, h, d]]))

EDIT 2 (May 2019)

"Kind of" on request (in a comment), a modernized / more advanced / improved (no system calls, no parsing but using Gdk.Display) version, doing pretty much exactly the same:

#!/usr/bin/env python3
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk

dsp = Gdk.Display.get_default()
n_mons = dsp.get_n_monitors()

print(("\t").join(["Screen", "width", "height", "diagonal\n"+32*"-"]))

for i in range(n_mons):
    mon = dsp.get_monitor(i)
    mon_name = mon.get_model()
    w = mon.get_width_mm()/25.4
    h = mon.get_height_mm()/25.4
    d = ((w**2)+(h**2))**(0.5)
    print(("\t").join([mon_name]+[str(round(n, 1)) for n in [w, h, d]]))

Output:

Screen  width   height  diagonal
--------------------------------
eDP-1   20.0    11.3    23.0
HDMI-1  18.6    11.7    22.0

I will leave the original answer, since it seems inappropriate to remove the answer after such a long time, that generated the existing votes.

Jacob Vlijm
  • 83,767
  • Just a side note, but both answers give me different results: xdpyinfo gives me "474x303 millimeters", and xrandr "473mm x 296mm". – agold Feb 18 '16 at 08:51
  • 1
    @agold Now that is interesting. A rounding difference. Another interesting thing is that xdpyinfo outputs the desktop size (both screens), not the screen's size! – Jacob Vlijm Feb 18 '16 at 08:54
  • @agold the difference is way too big for a rounding difference!! See my edit. – Jacob Vlijm Feb 18 '16 at 09:10
  • yes, it is quite big, but how do these programs get this information? Is it some meta information coming from the monitor, or is it estimated based on some other parameters...? – agold Feb 18 '16 at 09:13
  • @agold It seems to be related to a bug in xdpyinfo: https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/201491 ALthough the report is quite old, I don't see it fixed. Also see: https://bbs.archlinux.org/viewtopic.php?id=204823 – Jacob Vlijm Feb 18 '16 at 09:21
  • Good find! So I guess xrandr should be used then. – agold Feb 18 '16 at 09:23
  • It is actually a "bug" in X itself, where the DPI of the screen is set to 96x96 in lieu of actual DPI. Xdpyinfo only gets its info from X, xrandr is querying the screens directly. – Erbureth Feb 18 '16 at 10:46
  • File "./size.py", line 10, in <module> w = float(s[0].replace("mm", "")); h = float(s[2].replace("mm", "")); d = ((w**2)+(h**2))**(0.5)``` This is an error from the 1st python script. – Aleksandr Ryabov Oct 25 '18 at 22:38
  • @AleksandrRyabov Can't reproduce it, but please mention the full message: the error is missing. – Jacob Vlijm Oct 26 '18 at 05:44
  • @JacobVlijm, this is a full error:
    Traceback (most recent call last):
      File "./size.py", line 10, in <module>
        w = float(s[0].replace("mm", "")); h = float(s[2].replace("mm", "")); d = ((w**2)+(h**2))**(0.5)
    ValueError: could not convert string to float: 'axis'```
    
    The script that you showed in the first sample.
    
    – Aleksandr Ryabov Oct 29 '18 at 16:28
  • Unfortunately I think xrandr is buggy. my external 37.5" ultrawide monitor is shown as a 255mm x 255mm monitor, 10"x10" with the python script: DP-1-1 connected primary 3840x1600+0+0 (normal left inverted right x axis y axis) 255mm x 255mm 1920x1080 60.00 + 60.00 50.00 59.94
    3840x1600 30.00*
    – aless80 May 29 '19 at 06:47
  • @aless80 See updated answer. – Jacob Vlijm May 29 '19 at 10:20
  • @JacobVlijm Sorry to disappoint you but I still see a 10"x10" monitor. I am using a laptop with ultrawide monitor. the laptop is off. I tried xdpyinfo and at least it gave me a more reasonable value in my configuration, but when I disconnect the external monitor it looked wrong

    python3 get_dimensions.py Screen width height diagonal


    DP-1-1 10.0 10.0 14.2

    – aless80 May 29 '19 at 11:34
  • Hmm. I wish I could test on your resolution. Many things break on that. Are you using scaling? @aless80 – Jacob Vlijm May 29 '19 at 11:49
  • No I don't think. If you like I have the outputs of xrandr and xdpyinfo, but from Sunday on I'll stay offline for some weeks – aless80 May 31 '19 at 14:59
  • @agold: the source of this information ultimately comes from the monitor itself, retrieved from its EDID data – MestreLion Jul 01 '23 at 03:57
27

How'bout this :

xrandr | awk '/ connected/{print sqrt( ($(NF-2)/10)^2 + ($NF/10)^2 )/2.54" inches"}'

and through SSH :

ssh server DISPLAY=:0 xrandr | awk '/ connected/{print sqrt( ($(NF-2)/10)^2 + ($NF/10)^2 )/2.54" inches"}'

SebMa
  • 2,291
18

Just in case you want a more general answer, you can cut the the gordian knot, and use a non-geeky physical ruler for that. As per this wiki, the "size of a screen is usually described by the length of its diagonal":

enter image description here

If you have a ruler that only displays centimeters, you can use the simple conversion:

1 cm = 0.393701 in
(or 2.54 cm = 1 in)

So if your ruler measures 30 centimeters, your screen is 11.811 inches. You can also use google with a query of the form 30 cm to in.


Image credits: https://en.wikipedia.org/wiki/File:Display_size_measurements.png

phresnel
  • 283
  • 1
    Ask Ubuntu is a site for Software solutions, so your answer is a bit off-topic here... On the other hand, it's correct, well written, very readable and funny! :-) So upvoted! – Fabby Feb 22 '16 at 13:21
  • 2
    @dn-ʞɔɐqɹW: Actually, it's based on a mistake on my side. I read the question, "How can I get my laptop's monitor size?", and my first thought was "well, with a ruler", and before reading the complete question, I had my answer carved out the stone block. – phresnel Feb 22 '16 at 14:00
  • As a side note, one inch equals 25.4 mm exactly. – Paddy Landau Feb 22 '16 at 22:54
  • love that gordian knot reference – Todd Aug 25 '20 at 14:31
  • @Fabby, as per info on the page I saw, the question is for "linux command" and was edited before that answer was given, so the answer is not correct. – Martian2020 Feb 19 '22 at 01:08
8

Xdpyinfo is a utility for displaying information about an X server. It is used to examine the capabilities of a server, the predefined values for various parameters used in communicating between clients and the server, and the different types of screens and visuals that are available.

The command to get the monitor size is:

xdpyinfo | grep dimensions

Result

dimensions:    1366x768 pixels (361x203 millimeters)
Parto
  • 15,325
  • 24
  • 86
  • 117
  • 1
    Hi Parto, I really like your answer +1, however, look here: https://bbs.archlinux.org/viewtopic.php?id=204823 there is a huge difference in the dimensions xdpyinfo reports and xrandr. – Jacob Vlijm Feb 18 '16 at 09:19
  • @Jacob Something interesting - http://askubuntu.com/questions/378386/how-to-get-the-right-dpi-resolution-on-ubuntu-13-04-saucy – Parto Feb 18 '16 at 09:25
  • 1
    When measuring with a good old physical quality tape-measure, I get on my screen pretty much exactly the output of xrandr: 473mm, while xdpyinfo reports way too short (445mm). This question turns out to be more interesting then OP assumed I guess :) – Jacob Vlijm Feb 18 '16 at 09:32
  • it is 2022 and it is still incorrect on my device. – Martian2020 Feb 19 '22 at 01:10
0

This was something that I too was struggling with(when I wanted to upgrade to a new monitor for myself and wanted to know what size my old monitor was), so I wrote a shell script that finds the monitor size for you.

I used the xdpyinfo from the first answer to get the screen dimensions and built ahead on it. The script essentially computes the diagonal from the screen dimensions, converting from millimeters to inches and displays the result.

Repository URL: https://github.com/abhishekvp/WhatsMyScreenSize

Hope this helps!