Linux – Creating a symlink

Linux – Creating a symlink

I have been fully using Manjaro Linux for around eight months now. Mostly never using my Windows 10 except for the program Garmin Express that I need sometimes to update my garmin devices. Here’s my post about me finally leaving Windows for 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, only to find it’s not as easy as it seems to do

Linux is not Windows…

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

So a quick Google around showed me that I needed to do a 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.
The Source being where your original file is. My complete address (/usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg)
The 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 symlink files as having the little ‘arrow’ but also a ‘cross’, and when checking found that it was a ‘broken’ symlink. It was not quite right.

Now I had to delete this file. Doh…. I need to have root permission to do that ….
So again in teminal I typed the following.
sudo rm /usr/share/backgrounds/xfce/Wallpaper_1.jpg
Careful here rm is a very dangerous command. It deletes. Full stop. It doesn’t ask are you sure, “do you really want to do this ?” or any kind of message. So if you get it wrong and you could delete a wrong file. Be careful.

Solved

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 installed)

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 fairly easy. Except having to know that I had to a cd to be in my target folder for the symlink to be correctly created.

So I hope that this might save you some hours of googling around….

Here are two sites that I came across that also help and explain Creating a symlink, and probably better than me
https://www.freecodecamp.org/news/symlink-tutorial-in-linux-how-to-create-and-remove-a-symbolic-link/
https://linuxize.com/post/how-to-create-symbolic-links-in-linux-using-the-ln-command/

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 I hope that this helps.

Leave a Reply

Your email address will not be published.