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