Skip to content

Linux 101: How to create symbolic links in Linux

Symbolic links are a very important admin tool to use in Linux. Jack Wallen tells you why and how to create such links with ease.


Image: Pixabay

More about Open Source

Symbolic links (also called a soft link) are a very important tool to understand in Linux. These are special files that point to other files, similar to shortcuts in Windows or aliases in macOS. Symbolic links do not contain the data, but rather, a pointer to the actual file that does contain the data. 

By using symbolic links, you make it possible to more easily access other files that might reside in complicated directory paths or are required for certain services, such as enabling virtual host configurations in NGINX. In fact, without knowing how to use links, you’ll find some Linux administration tasks quite difficult. 

Let me show you how to use this feature. 

SEE: Linux file and directory management commands (TechRepublic Premium)

The idea behind creating a symbolic link is that you’re creating a link from the source to the destination. You must remember this, as it’s how the command is issued. The basic command for creating symbolic links is: 

ln -s original link

 We use the -s option to inform the ln command we’re creating a symbolic link. The original is the location of the file that contains the data and the link is the symbolic link. 

Let’s say you are using NGINX and you’ve created the mysite.conf virtual host configuration in /etc/nginx/sites-available. To enable that new site, you must create a symbolic link from /etc/nginx/sites-enabled to /etc/nginx/sites-available/mysite.conf. Because this also requires admin access, you will have to use sudo to make it work. 

To do that, you issue the command: 

sudo ln -s /etc/nginx/sites-available/mysite.conf /etc/nginx/sites-enabled/mysite.conf

 The important thing to remember here is the order: original/link. 

There are two ways to remove a link. You can use the unlink command, as in: 

unlink link 

Where link is the name of the link. Or, you can simply remove the link with the rm command, as in rm link (where link is the name of the link file). 

And that’s all there is to creating symbolic links in Linux. Enjoy that fresh linking power.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also see