Linux Tips : Creating a symlink

Follow My Blog on WordPress.com

Creating a symlink

I have now been fully using Manjaro Linux for around eight months now. Mostly never having to use my Windows 10 except for the program Garmin Express that I need sometimes. Here’s my post about me finally leaving Windows to Linux bit.ly/3jteVTm

Today I wanted to create a symlink (symbolic link) from an original file in a folder to another folder

In Manjaro Linux and probably other Linux distribs wallpapers are in more than one folder. The original files and symlinks are in different folders

I’d added a wallpaper image that I wanted to use in my /usr/share/backgrounds/wallpapers-2018/  folder and I wanted to add the symlink link to the /usr/share/backgrounds/xfce/ as this folder contained symlinks of all the original files in the wallpaper-2018 folder, why? I do not know, but as it must be of use somewhere and as I like playing and learning I thought that I would create the symlink

Linux is not Windows…

Of course, Linux not being Windows the copy, drag and drop doesn’t work as it needs root permissions.

So a quick Google around showed me that I needed the ln -s command in terminal

Terminal is your friend

So I typed in terminal what I had learned :

sudo ln -s /usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg /usr/share/backgrounds/xfce/

This is just sudo ln -s ‘source’ ‘target’

sudo so that it will ask your password when you hit the Ok button
Source being where your original fil is, the complete address (/usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg)
Target being where you want the symlink to be created (/usr/share/backgrounds/xfce/)

This effectively created a symlink in my target/destination folder /usr/share/backgrounds/xfce/ but I noticed that it was different from the other files having the little ‘arrow’ but also a ‘cross’, and when checking found that it was a ‘broken’ symlink.

Now I had to delete this file, doh needs to have root permission to do that ….
sudo rm /usr/share/backgrounds/xfce/Wallpaper_1.jpg
Careful here rm is a dangerous command, it deletes full stop and doesn’t ask are you sure etc etc

Hours later, many google pages later I came across an article saying that I had to ‘be in’ the target/destination folder when doing the ln -s command for it to work

Terminal is still your friend

Ok that’s fairly easy, so in the terminal I just typed
cd /usr/share/backgrounds/xfce/ (my target folder where I wanted the symlink to be)

Now being in the target folder I redid the
sudo ln -s /usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg /usr/share/backgrounds/xfce/

Creating a symlink : YES my symlink file was now created correctly and this time only having the little arrow showing me that it was a symlink and correctly linked to the original file. Oh yes 🙂

So easy except having to know that I had to cd to be in my target folder for the symlink to be correctly created

Hoping that this might save you some hours of googling around….

Her are two sites that I came across that also help and explain, probably better than me https://bit.ly/2V3cfCr https://bit.ly/3zAdFU9

Again I’m a beginner in Linux. I use it / play with it and sometimes find things that should be easy but aren’t and are as clear as mud, so help this helps

Follow My Blog on WordPress.com

Leave a Reply

Your email address will not be published. Required fields are marked *