Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I did an export DISPLAY=:1 in an X forwarded ssh session. Now I want to reset it back to its original value so that when I launch X apps they show up on my screen and not on :1. Is there any way to find what it was and set it to that ? Or does the value get lost irrevocably once it is overwritten ?

I don't want to have to restart ssh session just because I changed the value of DISPLAY.

share|improve this question

migrated from May 24 '12 at 14:47

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

You can save it into another variable first:

export DISPLAY=:1

To restore it back, do:


In case the DISPLAY variable was not saved, you can use the following code snippet (found here) to try to get its original value:

netstat -lnt | awk '
sub(/.*:/,"",$4) && $4 >= 6000 && $4 < 6100 {
    print ($1 == "tcp6" ? "ip6-localhost" : "localhost:") ($4 - 6000)

Remote displays correspond to open TCP ports above 6000; accessing display number N on machine M is done by connecting to TCP port 6000+N on machine M.

share|improve this answer
Actually, I am asking for the case where I did not save it. Is it possible to restore the display then ? I mean there must be some way to find out what the real display value is ! – AnkurVj May 24 '12 at 13:56
@AnkurVj I would say it is not possible to do that (unless you can guess the old value). Of course you can always restart the SSH connection. – betabandido May 24 '12 at 14:05
@AnkurVj Probably the display value was something like localhost:10.0. But that will depend on whether other X11 sessions are active. – betabandido May 24 '12 at 14:09
okay, that seems more effort than restarting ssh session. Although seems a legit hack to find out what I am looking for. Thanks ! – AnkurVj May 24 '12 at 14:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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