All¹ X11 programs open their windows on the display indicated by the environment variable DISPLAY
. Thus:
sudo -u 1000 env DISPLAY=:0 xev
or for that matter, since you can run programs as a different user from the X server, just
DISPLAY=:0 xev
:NUMBER
is the notation for local displays; in most scenarios, the X11 server that is running on the console is the one that's started first and ends up being number 0. You can run echo "$DISPLAY"
in a terminal on that display to check whether the display number is correct. :0.0
is equivalent to :0
(a trailing .0
can be omitted).
If you run the program as a different user from the X server, and sometimes even if you run it as the same user, you may need to set the XAUTHORITY
environment variable as well. This variable points to a file that contains a password (called a cookie) that applications must pass to the X server. To see the right value from XAUTHORITY
, run echo $XAUTHORITY
on that display; if it's unset, the default value is ~/.Xauthority
where ~
represents the user's home directory.
If you need to find the values of DISPLAY
and XAUTHORITY
programmatically, see Open a window on a remote X display (why "Cannot open display")?
¹ At least almost all. It's technically possible for them not to, but it takes active work on the part of the programmer to make it not so, whereas a -display
argument is a convention that is far from universal.
DISPLAY
. For Display0
you can doDISPLAY=:0 xev
. Now you will get an error about security X11 has security to stop you doing this. You need to look intoxauth
. Notexhost +
is dangerous. – ctrl-alt-delor Feb 19 '15 at 22:51