export DISPLAY=$(tr '\000' '\n' < /proc/`pidof Xorg`/cmdline | egrep '^:[0-9]+')

Find out local DISPLAY number

Not always does Xorg run on :0. For times like those, this script allows you to find out which it is.

-2
By: oernii2
2012-12-18 07:26:16

These Might Interest You

  • Display a list of local shell scripts soft-linked to /usr/local/bin Put local shell scripts to local ~/bin/ directory and soft-link them to /usr/local/bin/ which is in the $PATH variable to run them from anywhere. Show Sample Output


    0
    for AAA in $(find /usr/local/bin -type l); do ls -gG "${AAA}"; done
    rgregor · 2013-10-01 10:49:12 0
  • A common programming question for interviewers to ask potential job candidates is to code "FizzBuzz". That is, if a number is divisible by 3, then it should display "Fizz". If a number is divisible by 5, it should display "Buzz". If it is divisible by both, then it should display "FizzBuzz". Otherwise, display the current number between 1 and 100. Show Sample Output


    5
    python -c'for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i'
    atoponce · 2011-10-12 21:15:35 4
  • It's useful when you cannot access your env (systemd) or the process DISPLAY variable is not set. Perhaps also when you have a multi-head/user configuration. Show Sample Output


    1
    for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='\0' -F= '$1=="DISPLAY" {print $2}' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d
    geyslan · 2015-05-18 20:01:20 16
  • In some case, you need to use remote gui on servers or simple machines and it's boring to see "cannot open display on ..." if you forgot to export your display. Juste add this line in .bashrc on remote machine. Dont forget to allow remote client on your local X server : xhost +


    0
    [ -n "$SSH_CLIENT" ] && export DISPLAY=$(echo $SSH_CLIENT | awk '{ print $1 }'):0.0
    GouNiNi · 2010-04-14 08:19:37 3
  • Requires consolekit (works in e.g. Ubuntu). Here x11-display is DISPLAY Show Sample Output


    1
    ck-list-sessions
    unhammer · 2012-01-02 08:53:41 0
  • Broaden your knowledge of the utilities available to you in no particular order whatsoever! Then use that knowledge to create more nifty one-liners that you can post here. =p Takes a random number modulo the number of files in $dir, prints the filename corresponding to that number, and passes it as an argument to man.


    -2
    dir="/bin"; man $(ls $dir |sed -n "$(echo $(( $RANDOM % $(ls $dir |wc -l | awk "{ print $1; }" ) + 1 )) )p")
    camocrazed · 2010-08-20 16:31:50 1

What Others Think

You have something against this? echo $DISPLAY
TheMightyBuzzard · 283 weeks and 2 days ago
echo $DISPLAY is only good if you DISPLAY is set! When you run scripts from crontab, that is NOT the case.
oernii2 · 281 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: