list existing X display names?

How do I get a list of current X display names?

Apart from being a useful thing to know, I want this so that (hopefully!) I can use xcalib -invert -alter as suggested in this question to invert the second of two screens on my computer.


w

Yeah, that simple. That's an expanded version of who which shows who is logged in, and where they're connected from. That includes graphical sessions and that will show you all the current X displays, amongst other delicious data.

Here's what I see:

oli@bert:~$ w
 01:07:38 up 5 days, 58 min,  4 users,  load average: 0.40, 0.37, 0.41
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
oli      tty7     :0               Sat00    5days  4:22m  0.94s gnome-session --session=gnome-fallback
oli      pts/4    :0               Sat00   47:09m  0.77s  0.77s /bin/bash
oli      pts/6    :0               Wed02    0.00s  0.12s  0.00s w

You can file that down with various flags (try -hs) and then you can awk/grep away at that if you need to automate. Consider piping the resulting list through sort -u to get unique display strings. Something like this:

oli@bert:~$ w -hs | awk '{print $3}' | sort -u
:0