Linux Tips : 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.

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 in different folders

I had added wallpaper image that I wanted to use in  my /usr/share/backgrounds/wallpapers-2018/  folder
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

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

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

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/

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….

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

Feel free to leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s