Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The title is quite exhaustive: is there a way to retrieve the desktop environment name (e.g. Gnome, Unity, XFCE, LXDE, KDE...) from the command line or using Python?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

In a Terminal input:

share|improve this answer
great! thank you very much –  giuspen Aug 25 '12 at 15:22
Note that this will not always work as sometimes DESKTOP_SESSION is set to "Default" or in some cases not set at all (I think it's gdm/kdm that set this variable). A better approach would be to check for the running session process. –  don_crissti Aug 25 '12 at 17:39
I noticed there's also a varable XDG_CURRENT_DESKTOP="LXDE" (or "Unity", in my two desktops), do you think it's reliable? –  giuspen Aug 26 '12 at 8:58
@giuspen - discussed also here link. XDG_CURRENT_DESKTOP is just a proposal, it's not part of the XDG spec and is discussed on various mailing lists, e.g. link. FIY I am on Gnome3/Arch64bit, I have all the xdg-* packages installed and this variable is unset. –  don_crissti Aug 26 '12 at 13:11
@don_crissti - thanks I read in the other discussion that you linked that XDG_CURRENT_DESKTOP is deprecated. I will try to look at the running processes. –  giuspen Aug 26 '12 at 14:50

The question is rather broad... I think it all depends on what you are trying to accomplish. I would check for the running desktop-session / wm / desktop-shell and only use environment variables as a complement, if at all.
Something like this:

pgrep -u $USER -xl "gnome-session|ksmserver|lxsession|mate-session|xfce4-session|whatever"

should return the current user running session. With so many forks (and forks on forks) the user might be using a different shell with that particular DE so you would have to check that too, e.g.:

pgrep -u $USER -xl "gnome-shell|plasma-desktop|unity-stuff|etc"

Then, some people use different WMs with those DEs. Some don't use a fully-fledged DE and opt for minimalist desktop managers or WMs on top of X. You could run:

pgrep -u $USER -xl "awesome|beryl|blackbox|compiz|dminiwm|dwm|e16|emerald|enlightenment|fluxbox|fvwm|i3|icewm|kwin|metacity|monsterwm|muffin|musca|openbox|pekwm|ratpoison|sawfish|scrotwm|stumpwm|subtle|wmaker|wmfs|wmii|xfwm4|xmonad"

But even then, you would still miss some stuff (e.g. mutter). Again, it all depends on your goals (ideally, you'd have to get familiar with the particulars of each DE+shell/WM in order to be able to get the expected result).

share|improve this answer

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.