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
Was it useful? Share this post with the world!

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

  1. Lokesh Mohanty says: Reply

    Thanks a lot.

    1. Gajju

  2. Дмитрий says: Reply

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

    1. Не ls, а ln

  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

  5. Hello sir may i know symbolic link linux using what port??

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

  7. Not working, getting error “No such file or directory”…

  8. Thanks man, the part i was doing wrong is to use an existing directory as a symbolic link.

Leave a Reply