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.

1 Answer 1


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
  • 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, 2012 at 2:54
  • I added a xcalib question here in case you're interested.
    – drevicko
    Dec 20, 2012 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, 2013 at 10:03
  • 1
    Nitpick: It seems this won't pick up X displays that aren't logged into, such as the X display used by a GDM login screen. These can be found a bit messily via searching processes, e.g. ps aux | grep X, but you separately need w or who to see the displays used by logged in users, it seems.
    – Gertlex
    Sep 3, 2020 at 18:17
  • No need for sort. w -hs | awk '!u[$3]++{print $3}' :P Jul 23, 2021 at 1:29

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.