A symbolic link, also known as a symlink or a soft link, is a special kind of file (entry) that points to the actual file or directory on a disk (like a shortcut in Windows).
Symbolic links are used all the time to link libraries and often used to link files and folders on mounted NFS (Network File System) shares.
ln command is a standard Linux utility for creation links.
Cool Tip: Creating a symlink to a mounted NFS? Have you already thought about performance? Test the READ/WRITE speed to a remote share from the Linux command line! Read more →
Below you’ll find how to create a symbolic link to a file and a folder from the Linux command line.
Create SymLink in Linux
Easy to remember: Generally, the
ln syntax is similar to the
mv syntax, e.g. <source> <destination>.
Use the following syntax to create a symbolic link in Linux:
$ ln -s <SOURCE> <LINK_NAME>
Nevertheless you should know, that according to the
man page, by default, each destination (<LINK_NAME>) should not already exist.
If the path to the <LINK_NAME> exists and it is a file, you will get an error like “ln: failed to create symbolic link ‘<LINK_NAME>’: File exists”.
But if the path to the <LINK_NAME> is an existent directory, link will be created inside that directory.
Example: SymLink to a File
Create a symbolic link to a file:
$ ln -s /path/to/file /path/to/symlink
Example: SymLink to a Directory
To create a symbolic link to a directory you should use exactly the same syntax as for creating a symlink to a file.
Cool Tip: Have added a new drive to
/etc/fstab? No need to reboot! Mount it with one command! Read more →
Create a symbolic link to a directory:
$ ln -s /path/to/dir /path/to/symlink
11 Replies to “SymLink – HowTo: Create a Symbolic Link – Linux”
Thanks a lot.
Что я делаю не так? Почему у меня не создаётся ссылка?
Hello i try doing this but I have a message that says that the files exists and it doesn’t work
you have to give another name to the symlink, an example:
ls -s file.txt linkFile.txt
and then you can update the linkFile.txt and the file.txt would be affected with the modifications that you made to linkFIle.txt
You have to make the link in another directory, otherwise there is no point in making a link.
ln -s dir1 dir2
Hello sir may i know symbolic link linux using what port??
you can create symbolic links to directories you find yourself often having to type the full path to.
For instance, instead of finding yourself repeatedly typing /var/log to enter that directory, just create symlinks to /var/log in many various directories…so that when you want to switch to /var/log, you can just type “cd log”.
This way you can create a symbolic link to /var/log under /bin, /usr/bin/, /tmp, /root, /home, /etc, /whatever! Whenever you are away from /var/log and you want to go there quickly, just type cd log, rather than the whole (absolute) path.
Not working, getting error “No such file or directory”…
Thanks man, the part i was doing wrong is to use an existing directory as a symbolic link.