SymLink – HowTo: Create a Symbolic Link – Linux

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.

The 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 cp or mv syntax, e.g. <source> <destination>.

Use the following syntax to create a symbolic link in Linux:

$ ln -s <SOURCE> <LINK_NAME>

As you can see, there is nothing hard in creating symlinks.

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

6 Replies to “SymLink – HowTo: Create a Symbolic Link – Linux”

  1. Thanks a lot.

  2. Что я делаю не так? Почему у меня не создаётся ссылка?

  3. Hello i try doing this but I have a message that says that the files exists and it doesn’t work

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

  4. You have to make the link in another directory, otherwise there is no point in making a link.
    ln -s dir1 dir2

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.