Symlink, short for Symbolic Link, is a special type of file/folder that points or references to another physical file/folder in the system. When clicked, it will follow the link that it references to, yet maintaining its link structure. For example, when click on a symlink on the Home desktop that is pointing to the Backup folder in another partition, the content of the Backup folder will show up, but the link structure is still under the symlink folder in the Home directory. Symlink is a good way to access files and folders that are out of reach, or difficult to reach and it is widely used in Unix-like Operating System. It is also available in Windows 7 & Vista, but only users with the “Create Symbolic Link” privilege, which only administrators have by default, can create symbolic links.
The Advantages of using Symlink
The main advantage of symlink is that it is easy to create and doesn’t affect the system when deleted. Creating a symlink on your local folder pointing to the backup folder in the Network Drive makes it easier for you to access your files. Similarly, Dropbox users who wanted to sync multiple folders outside of the Dropbox folder can make use of symlink to get files synced easily.
In web hosting environment (particularly LAMP server), symlinks are heavily used to bring other parts of the filesystem to the Server Root. This allows the web administrator to have more flexibility in organizing and serving files to the Web.
On the other hand, when the targeted folder is moved or deleted, the symlink will fail to work. If you have created a lot of symlink and you love to move your folders around, you will have a lot of dead symlinks lying around. While they don’t take up plenty of space, they can become unsightly and mess up your filesystem.
Also, creating a symlink does not change the underlying user-permission of the files. If you create a symlink on your Home folder, pointing to a folder in the root directory, the file user-permission will not change. You will be able to access the files inside the folder, but you won’t be able to place files or edit the files in the symlink folder.
How to Create Symlink
The command line way
To create a symlink with the command line, you just have to use the command
ln with the
-s flag. The syntax is as follow:
ln -s TARGET_FOLDER SYMLINK_FOLDER
For example, if you want to create a symlink on your Dropbox folder to sync all the beautiful wallpapers you have collected over the years, here is how you can do it via the command line:
ln -s /home/username/wallpaper /home/username/Dropbox/wallpaper
The above command will create a symlink folder named “Wallpaper” in the Dropbox folder, pointing to the “Wallpaper” folder in the Home directory. Any wallpaper you place in the Wallpaper folder will automatically sync to Dropbox.
Note: For illustration purpose, I am using absolute path in the above example. You can use relative path as well.
The file manager way
I don’t have the chance to use all file managers to test this function, but in Nautilus, you can easily create a symlink by righ-clicking a file/folder and select “Make Link”.
This will create a symlink file/folder in the same directory as the targeted file/folder. It should be easily identifiable with a symlink icon.
You can then rename the symlink and move it to another location. The relocation of the symlink won’t affect the result, but the relocation of the target file/folder will.
Managing the symlink
If you have no more use for the symlink, you can simply delete it and it won’t affect any file/folder in your system.
To change the target folder it is pointing to, there is currently no way to do it. You will have to delete the symlink and create another symlink pointing to another folder.
Is this article useful to you? Let us know in the comments.
Image credit: Link by Big Stock Photo.