20

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.

24
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
  • 2
    wonderful! I thought it would be simple, didn't expect a single character command though ;) Unfortunately it doesn't solve my xcalib problem though - I'll ask it in another quesion. – drevicko Dec 20 '12 at 2:54
  • I added a xcalib question here in case you're interested. – drevicko Dec 20 '12 at 3:09
  • with KDE I'm getting username :0 ?xdm? /bin/sh /usr/bin/startkde as the first line, so ?xdm? gets shown instead of :0. Any way to avoid this? – int_ua Oct 13 '13 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.