In this tutorial, we will show you how to create Symbolic Links on Linux. For those of you who didn’t know, A symbolic link, also known as a symlink or soft link is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows. 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.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step create Symbolic Links with practice examples.
Create Symbolic Links on Linux
- Command to Create Symbolic Links.
ln is a command-line utility for creating links between files. By default, the
ln command creates hard links. To create a symbolic link, use the
ln [-sf] [source] [destination]
For example, create a symbolic link with:
ln -s my_test_file.txt my_link_file.txt
To verify that the symlink was successfully created, use the
ls -l my_link_file.txt
- Create a Symbolic Link to Linux Directory.
To create a symbolic link to a directory in Linux:
ln -s /mnt/external_drive/stock_movies ~/stock_movies
The above example creates a symbolic link named
stock_movies on the
home (~/) directory. The link refers to the
stock_movies directory on an
- Unlink to Remove a Symlink.
You can remove existing links attached to files or directories by the
rm my_link_file.txt unlink my_link_file.txt
Congratulations! You have successfully learned to create Symbolic Links. Thanks for using this tutorial to cover how to use the
ln command to create symbolic links on your Linux system.