For servers, symlinking is very useful. Are you a Linux user? Then symlink can also help you a lot. All you have to do is be creative with it to lessen your workload.
Power of symlink
There are a lot of complex directories in the file system of Linux, right? Remembering all of them can be a real hassle. Moreover, when you want to work with a file/directory that’s deep within directories and sub-directories, the file path length becomes longer.
It’s especially a pain when working with CLI where you have to specify the file paths. Here comes the symlink to help.
For example, you want to access “/home/<username>/Downloads/a/b/c/d/e.txt” file. This is an easy demo, but surely typing the entire file length isn’t something you want to do often, right? With the power of symlink, you can dramatically reduce the file path to “/home/e.txt”.
Here, the symlink feature allows you create a virtual file at “/home/e.txt” that indicates to the “/home/<username>/Downloads/a/b/c/d/e.txt”. Whenever you ask for “/home/e.txt” file to manipulate, the system will work on the original file.
The same method goes for directories as well.
Today, let’s check out all how to create a symlink and have fun with it.
Creating Symlink
On all the Linux systems, there’s a tool “ln”. Don’t confuse with natural logarithm! “ln” follows the same structure of “cp” and “mv”. Learn more about copying file(s) and directories on Linux.
For example, let’s create a symlink of “/home/viktor/Downloads” to “/Downloads”.
It’s time to verify the result. Note that you can easily verify the result with a command that works using that directory or file. For example,
I’m now inside “/Downloads” directory. It’s actually not a new directory. Instead, it’s a link to the original “/home/viktor/Downloads” folder.
Verify that both are the same –
ls
cd /Downloads
ls
See? Both of them are the same!
Let’s do the same with a file. I have already set a demo file “pimusic.txt” on “/home/viktor/Desktop”. Let’s link it as “PIMUSIC”.
Verify the result –
Creating permanent symlink
Note that the symlinks you create aren’t permanent. Whenever you reboot your system, you have to recreate the symlink again. To make them permanent, simply remove the “-s” flag. Note that it will create a HARD LINK.
Verify the result after rebooting the system –
Enjoy!