1. Overview

We may wish to change the wallpaper of our Linux desktop. Using the graphical user interface is a common choice. However, we may also wish to change the settings from the command line.

In this tutorial, we’ll see how to use the terminal to change our desktop wallpapers with some of the common desktop environments.

2. Identifying the Desktop Environment

Before changing our wallpaper, we should first determine which desktop environment we’re using.


For many desktops, the DESKTOP_SESSION environment variable will be set to the name of our current desktop environment:


Here we can see that the value is set to gnome, so we must be running the Gnome desktop environment. This will be set to mate for the Mate desktop environment, and so on.

However, this variable may not be supported across all environments.


Let’s see an example where DESKTOP_SESSION isn’t much help:

# OR

In this situation, we can look at XDG_CURRENT_DESKTOP instead:


2.3. From the wmctrl Tool

If the environment variables don’t help, then we can use the wmctrl command to get information about the window manager and environment:

$ wmctrl -m
Name: GNOME Shell
Class: N/A
Window manager's "showing the desktop" mode: OFF

As we can see, the desktop environment here is Gnome, as displayed in the Name label.

3. Setting the Desktop Wallpaper

Let’s look at how to change the wallpaper from a script for the most commonly used desktop environments: Gnome, Cinnamon, MATE, KDE, and Xfce.

3.1. For Gnome, MATE, and Cinnamon

The Gnome, MATE, and Cinnamon desktop environments use gsettings to manage their configuration settings. Therefore, we can use it, coupled with the set sub-command, to change the background for our Gnome desktop:

$ gsettings set org.gnome.desktop.background picture-uri file:///home/cic/wallpaper.jpg

The above command uses the org.gnome.desktop.background path, which controls the background image (and color). It assigns the file path of an image (/home/cic/wallpaper.jpg) to the picture-uri setting to use it as a desktop background.

Using the same command, we can change the desktop background for MATE:

$ gsettings set org.mate.desktop.background picture-uri file:///home/cic/wallpaper.jpg

And also for Cinnamon:

$ gsettings set org.cinnamon.desktop.background picture-uri file:///home/cic/wallpaper.jpg

3.2. For Xfce

When it comes to an Xfce desktop environment, we can rely on managing the Xconf configuration system. In this case, we’ll use the xfconf-query command to modify the wallpaper configuration in Xfconf:

xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor1/workspace0/last-image \
-s /home/cic/bouhannana.jpg

As seen above, the command uses the -c (abbreviation of –channel) switch to select the xfce4-desktop configuration channel. We also use the -p (short for –property) switch to specify the property we want to change (desktop background).

Lastly, we use the -s (abbreviation of –set) option to assign a new value for the property, which is the file path of the background we want to use for our desktop (/home/cic/bouhannana.jpg).

3.3. For KDE

So far, we’ve explored some relatively straightforward methods for changing the desktop background. However, things can get a little bit trickier when dealing with a KDE desktop environment.

To change it for KDE, we can use the dbus-send command, providing some JavaScript code:

$ dbus-send --session --dest=org.kde.plasmashell --type=method_call \
/PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:
var Desktops = desktops();
for (i=0;i<Desktops.length;i++) {
        d = Desktops[i];
        d.wallpaperPlugin = "org.kde.image";
        d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
        d.writeConfig("Image", "file:///home/cic/bouhannana.jpg");

The script above sets a new desktop background using plasma shell scripting. It will get all desktops in the environment. Then it sets the wallpaper for each desktop to the specified image path (/home/cic/bouhannana.jpg).

If this method doesn’t work, we can try the qdbus command:

$ qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "
    var Desktops = desktops();
    print (Desktops);
    for (i=0;i<Desktops.length;i++) {
        d = Desktops[i];
        d.wallpaperPlugin = 'org.kde.image';
        d.currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
        d.writeConfig('Image', 'file:///home/cic/bouhannana.jpg')

At first glance, we notice that the qdbus command used fewer arguments to execute the same JavaScript code, so it may be a little easier to use.

4. Conclusion

In this tutorial, we’ve discussed how to change our desktop wallpaper in Linux from the terminal.

First, we looked at how to find out which desktop environment we’re using.

Then we saw the commands that can be used to accomplish this for Gnome, MATE, Cinnamon, Xfce, and KDE environments.

Comments are closed on this article!