A symbolic link in Linux is a type of file in Linux that points to another file or a folder on your computer. Here we will show you how to create a symbolic link in Linux.
Create Symbolic Link (Soft Link)
Use the ln command with the -s directive to create a soft link with the following syntax:
$ ln -s /path/to/originalfile /path/to/linkfile
Here is an example implementing the above syntax:
$ ln -s /var/www/html/config.php /home/user/config.php
Compare the inode numbers of the symbolic soft link and the original file:
$ ls -li /var/www/html/config.php /home/user/config.php
4089832 lrwxrwxrwx 1 root root 11 Jan 07 08:47 /home/user/config.php -> /var/www/html/config.php
5780987 -rw-r--r-- 1 root root 24 Aug 12 10:22 /var/www/html/config.php
Create Hard Link Example
$ ln /var/www/html/config.php /home/user/config.php
The above is run without the -s directive.
Again let’s compare the inode numbers of the hard link and the original file:
$ ls -li /var/www/html/config.php /home/user/config.php
5780987 -rw-r--r-- 1 root root 24 Aug 12 10:22 /home/user/config.php
5780987 -rw-r--r-- 1 root root 24 Aug 12 10:22 /var/www/html/config.php
That’s it for create symbolic link for now. Remember to follow this post to read more about the differences between a soft link and a hard link in Linux.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.