53

Is there a command that will list displays connected to the computer?

Specifically, I'm looking to find out how my external monitor is being detected by the system when connected by HDMI cable and what it's (not sure of the correct term here) hardware address is (eg. "CRT-0" or "DFP-1").

This is just a general question, but for reference, I'm using:

  • Asus UL30JT laptop - running Ubuntu 12.04 beta and 11.10
  • Asus PA238 23" monitor
  • HDMI 1.4 cable
  • Optimus graphics (Intel + nVidia GeForce 310M) - running with Bumblebee
Erland
  • 731

4 Answers4

62

Try this:

xrandr --query
xrandr --listactivemonitors

This lists the display names and detected available resolutions. You can also reconfigure your displays using xrandr.

Note that this might not work if you're using the ATI drivers; I'm not sure.

opyate
  • 113
  • 1
  • 8
ams
  • 3,099
  • 4
    xrandr only works when you run it under X-windows. After all, it is X that handles all but the most basic video drivers. If you are in a terminal inside X and it still doesn't work, then you've most likely lost your $DISPLAY environment variable, somehow. – ams Apr 18 '12 at 08:44
  • 2
    Don't forget to add -display :0.0 if trying this from remote log-in (putty?). – Nikola Malešević Mar 05 '15 at 00:31
  • 4
    xrandr --query | grep '\bconnected\b' if you just wanted to see the connected monitors and their resolutions. – mpen Dec 23 '15 at 16:40
  • @NikolaMalešević Now it's changed from Can't open display to Can't open display :0.0 :| – endolith Dec 10 '18 at 03:25
  • @mpen xrandr --listconnectedmonitors surely? – Rich Sep 25 '19 at 21:14
  • @Rich The correct option is xrandr --listactivemonitors, at least today. – adamency Apr 02 '24 at 01:53
12

For most machines with the proprietary driver loaded, /usr/lib/nvidia-current/bin/nvidia-xconfig --query-gpu-info --nvidia-cfg-path=/usr/lib/nvidia-current works. Note that I said "with the proprietary driver loaded". For instance, it does not work if the driver is unloaded or nouveau is loaded. Therefore, when using Bumblebee, run optirun /usr/lib/nvidia-current/bin/nvidia-xconfig --query-gpu-info. The --nvidia-cfg-path part is not needed here as optirun sets the correct library path.

See also the discussion on https://github.com/Bumblebee-Project/Bumblebee/issues/21

/var/log/Xorg.0.log (where 0 is the display number) may also contain valuable information about available screens. For Optimus laptops, this log contains only details on the Intel screen, so replace 0 by 8 to find out the log from the X server started by Bumblebee.

Lekensteyn
  • 178,864
6

All other answers only work in specific situations.

@ams's answer requires the $DISPLAY environment variable being set and thus does not work via SSH.

@Lekensteyn's answer obviously only works with nvidia GPUs.

Universal Solution for systems running on X display server

The only infallible solution is to look at the open display unix sockets by the X server, i.e. listing the directory /tmp/.X11-unix/

Ex:

root@host # ls /tmp/.X11-unix/
total 0
srwxrwxrwx 1 root root 0 Apr  2 01:06 X0
srwxrwxrwx 1 root root 0 Apr  2 01:06 X1

This would mean that two displays, respectively called :0 and :1, are connected to the machine.

adamency
  • 182
  • 1
  • 5
  • 1
    Not really "universal" unless you forget Wayland – muru Apr 02 '24 at 03:32
  • 1
    @muru you're right. Previous conversations were all about X, so I didn't realize the question wasn't specifically framed at X, but then again it was 12 years ago. I changed my answer accordingly. – adamency Apr 02 '24 at 21:30
  • Some other possible solutions for finding $DISPLAY values can be found at https://superuser.com/questions/647464/how-to-get-the-display-number-i-was-assigned-by-x . Not sure if any of them work in Wayland. – mwfearnley May 30 '24 at 08:47
  • @mwfearnley This is not what the question asks, nor the objective of my answer. Please pay attention to the context. – adamency Mar 04 '25 at 22:21
  • @adamency A little tardy, but thanks for the feedback. – mwfearnley Mar 05 '25 at 08:51
1

The undermentioned .sh code should perform what you request:

#!/usr/bin/env -S bash
set -x

Updates package selection

sudo apt update && \

Installs the package

sudo apt install -y 'hwinfo' && \

Invokes the installed package

hwinfo --monitor

An example of its output for me is:

72: None 00.0: 10002 LCD Monitor                                
  [Created at monitor.125]
  Unique ID: rdCR.LqF49Z4qR41
  Parent ID: svHJ.Zzd7VOLabX6
  Hardware Class: monitor
  Model: "AOC Q3279WG5B"
  Vendor: AOC "AOC"
  Device: eisa 0x3279 "Q3279WG5B"
  Serial ID: "19441"
  Resolution: 720x400@70Hz
  Resolution: 640x480@60Hz
  Resolution: 640x480@67Hz
  Resolution: 640x480@72Hz
  Resolution: 640x480@75Hz
  Resolution: 800x600@56Hz
  Resolution: 800x600@60Hz
  Resolution: 800x600@72Hz
  Resolution: 800x600@75Hz
  Resolution: 832x624@75Hz
  Resolution: 1024x768@60Hz
  Resolution: 1024x768@70Hz
  Resolution: 1024x768@75Hz
  Resolution: 1280x1024@75Hz
  Resolution: 1920x1080@60Hz
  Resolution: 1280x1024@60Hz
  Resolution: 2560x1440@60Hz
  Size: 725x428 mm
  Year of Manufacture: 2018
  Week of Manufacture: 25
  Detailed Timings #0:
     Resolution: 2560x1440
     Horizontal: 2560 2568 2600 2666 (+8 +40 +106) -hsync
       Vertical: 1440 1443 1448 1481 (+3 +8 +41) +vsync
    Frequencies: 296.00 MHz, 111.03 kHz, 74.97 Hz
  Year of Manufacture: 2018
  Week of Manufacture: 25
  Detailed Timings #1:
     Resolution: 2560x1440
     Horizontal: 2560 2608 2640 2720 (+48 +80 +160) +hsync
       Vertical: 1440 1443 1448 1481 (+3 +8 +41) +vsync
    Frequencies: 241.50 MHz, 88.79 kHz, 59.95 Hz
  Driver Info #0:
    Max. Resolution: 2560x1440
    Vert. Sync Range: 48-76 Hz
    Hor. Sync Range: 114-114 kHz
    Bandwidth: 296 MHz
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #1 (VGA compatible controller)

73: None 01.0: 10002 LCD Monitor [Created at monitor.125] Unique ID: wkFv.08rGJ7kUoc8 Parent ID: svHJ.Zzd7VOLabX6 Hardware Class: monitor Model: "AOC Q3279WG5B" Vendor: AOC "AOC" Device: eisa 0x3279 "Q3279WG5B" Serial ID: "40899" Resolution: 720x400@70Hz Resolution: 640x480@60Hz Resolution: 640x480@67Hz Resolution: 640x480@72Hz Resolution: 640x480@75Hz Resolution: 800x600@56Hz Resolution: 800x600@60Hz Resolution: 800x600@72Hz Resolution: 800x600@75Hz Resolution: 832x624@75Hz Resolution: 1024x768@60Hz Resolution: 1024x768@70Hz Resolution: 1024x768@75Hz Resolution: 1280x1024@75Hz Resolution: 1920x1080@60Hz Resolution: 1280x1024@60Hz Resolution: 2560x1440@60Hz Size: 725x428 mm Year of Manufacture: 2019 Week of Manufacture: 51 Detailed Timings #0: Resolution: 2560x1440 Horizontal: 2560 2568 2600 2666 (+8 +40 +106) -hsync Vertical: 1440 1443 1448 1481 (+3 +8 +41) +vsync Frequencies: 296.00 MHz, 111.03 kHz, 74.97 Hz Year of Manufacture: 2019 Week of Manufacture: 51 Detailed Timings #1: Resolution: 2560x1440 Horizontal: 2560 2608 2640 2720 (+48 +80 +160) +hsync Vertical: 1440 1443 1448 1481 (+3 +8 +41) +vsync Frequencies: 241.50 MHz, 88.79 kHz, 59.95 Hz Driver Info #0: Max. Resolution: 2560x1440 Vert. Sync Range: 48-76 Hz Hor. Sync Range: 114-114 kHz Bandwidth: 296 MHz Config Status: cfg=new, avail=yes, need=no, active=unknown Attached to: #1 (VGA compatible controller)

Luckily, this is independent of the display server (and compositor) so this functions on Wayland too.