Ubuntu – How to get the laptop’s monitor size


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


Best Answer

  • Another option, using xrandr, is the command:

    xrandr | grep ' connected'


    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]


    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:
                float(s[-3].replace("mm", "")),
                float(s[-1].replace("mm", ""))
        except ValueError:
    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]]))


    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.