I've tried gconftool and gconftool-2 to change the background on my Wheezy, but nothing happens. It would be nice to be able to do this from the command line.
7 Answers
For the sake of providing an answer specific to raspbian.
The background is set via /etc/alternatives/desktop-background
so the background can be changed through two different ways:
sudo update-alternatives --config desktop-background
and you will get a list to choose from. Those are background provided by packages.- manually overwrite the
/etc/alternatives/desktop-background
symlink to the file you want to use as background.
-
works, but needs you to logout and login back in again to see the change Commented Apr 6, 2015 at 9:51
-
2On my Raspbian,
/etc/alternatives/desktop-background
appears to be a binary file. The per user desktop wallpaper is in the home directory's.config/pcmanfm/LXDE-pi/desktop-items-0.config
– u936293Commented May 14, 2015 at 5:43 -
Why is user2 desktop settings stored under /home/pi/.config/pcmanfm/LXDE-pi/desktop-items-0.conf and not under /home/user2/.config/pcmanfm/LXDE-pi/ ?– MeryanCommented May 12, 2021 at 1:13
None of the above worked for me. So here is the solution for Raspbian Stretch
pcmanfm --set-wallpaper yourfile.jpg
The file can be on any path that is available to read by the user. Here I have assumed it to be /home/pi.
-
you probably want to set the display first on RPi4
export DISPLAY=:0.0
followed bypcmanfm --set-wallpaper yourfile.jpg
– BhavCommented Feb 5, 2020 at 5:22
I've been trying to find a solution to this for ages - with all other attempts failing - and finally came up with a solution what works!
Caveat: This is using Buster on a RasPi4, and I've not tested on the other OSs or Pis.
Steps:
- Locate your
desktop-items-*.conf
file. Mine are in~/.config/pcmanfm/LXDE-pi
. - Use
sed
to replace the filename in the config file(s). (I have two as I'm using two monitors). - Reload
pcmanfm
The Command:
sed -i 's/\(rpd-wallpaper\/\).*/\1fjord.jpg/g' desktop-items-*.conf && pcmanfm --reconfigure
In this case, replace fjord.jpg
with your desired file.
I'm planning to set this up as a cron job which runs every (n) minutes, but have not tested this yet.
This depends somewhat on which DE you are using. Raspbian by default uses LXDE, so if you search online for "LXDE change background" you will find some suggestions, such as right-clicking on the desktop.
Something which tends to work universally, in my experience, is:
display -window root /your/image/file
If the display
command is not found, apt-get install imagemagick
.
However, ideally you should use LXDE's mechanism (presuming LXDE really is your desktop environment), if you can find it, since this will make it easier to keep permanent.
-
I can't right click, I don't have a mouse on this Pi.– user9702Commented Jul 24, 2014 at 14:25
-
The display command didn't work for me on Raspbian Jessie Commented Aug 29, 2016 at 21:02
Raspberry Pi with the standard X-Windows. I use:
pcmanfm -w /home/username/image.jpg
Then I rotate this in a bash script.
As goldilocks sayed, to simply change your desktop background on linux :
display -window root /your/image/file
To change your lock-screen background Manually on linux debian (here wheezy version) :
1 - Verify that symbolic link on lock-screen background exists : sudo ls -l /etc/alternatives/desktop-background ;
2 - change manually the symbolic link to link the new background : sudo unlink /etc/alternatives/desktop-background ; sudo ln -s /home/MyFirstUserHome/background-fake/a_background.jpg /etc/alternatives/desktop-background
3 - Try to lock your screen to see if the changes took effect
If this solution doesn't work, it means that an xml file probably handle different resolutions associated with their own shortcut to their image_file (on wheezy debian obviously...).
So you need to verify your resolution (Settings -> Display), and try to add your configuration in the file with your favourite editor : (Example using gedit for the example)
1 - sudo apt-get install gedit ; 2 - sudo cat /usr/share/images/desktop-base/joy.xml ;
<background>
<static>
<duration>8640000.0</duration>
<file>
(.....the configuration per resolution ...)
</file>
</static>
</background>
3 - search the configuration line corresponding to your resolution : Example if my display resolution is 1920x975 :
<size width="1920" height="975">here_is_the_path/background.svg</size>
Note : If you can't find the line corresponding to your resolution, add the line with a text-editor because the width and height values of the configuration line must correspond exactly to your display resolution setting.
4 - replace the background-path of the line or create the line if necessary :
<size width="1920" height="975">/home/Me/background/test.jpg</size>
5 - Save the file and try again to look the lock-screen background !
4 - If all of that doesn't work it seems to be a big mistake !
Hoping that helped ..
If running a recent version of Raspbian (Debian wheezy), you can simply go to Menu, select Preferences, then Appearance Settings, and under Picture select the .png file you want for your background, and it changes right away.
-
2The original question asked specifically for a way to do it through the command line, and I wouldn't consider Wheezy to be recent. Commented Mar 28, 2016 at 15:08