×

Do you know what soft ("symbolic") links are? Need to create a soft link (symbolic link) on your Linux operating system?

This guide will help you.


Symbolic links make it possible for making links between files.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our customers to Solve Linux related issues.
In this context, we shall look into the steps to create symbolic/soft links.

More about symbolic or soft links?

Basically, a symbolic link (also known as a soft link or symlink) is made up of a special type of file that serves as a reference to another file or directory. This can be implemented with the "ln" command.
This sort of linking is very common on Linux Operating Systems.
There are two types of links namely;
i. Symbolic links (also known as "soft links" or "symlinks"): This Refer to a symbolic path indicating the abstract location of another file.
ii. Hard links : This Refer to the specific location of physical data.

How to create soft link / symbolic link on your Linux System?

With the ln command, you can easily create a symbolic link. For instance, if you want to create a soft link named "link-one" to a file named "file-one", both in the current directory, simply execute the following command;

ln -s file-one link-one


Then to verify the newly created symbolic link, simply execute;

ls -l file-one link-one


You will get an output such as;

-rw-r--r--  1 veryv  wheel  0 April  7 22:01 file-one
lrwxr-xr-x  1 veryv  wheel  5 April  7 22:01 link-one -> file-one


You can see that from the above outputs it is clear that a symbolic link named "link-one" contains the name of the file named "file-one" to which it is linked.

How to make use of ln command for creating a symbolic link?

To create a symbolic link in Linux, start by logging into your Server via an SSH tool such as putty and once logged into the server at the shell prompt, execute the following command;

ln -s {source-filename} {symbolic-filename}


Lets say we want to create a softlink for /root/home/httpd/test1.com/index.php as /home/user/index.php, then execute the following commands;

ln -s /root/home/httpd/test1.com/index.php /home/user/index.php
ls -l

You will get an output such as this;

lrwxrwxrwx 1 user  user    16 2020-09-25 22:53 index.php -> /root/home/httpd/test1.com/index.php


So you can modify the soft link named /home/user/index.php and /root/home/httpd/test1.com/index.php will get updated as seen below;

vi /home/user/index.php


Then your actual file /root/home/httpd/test1.com/index.php remains on disk even if you deleted the soft link /home/user/index.php using the rm command as shown below;

rm /home/user/index.php ## <--- link gone ##

## But original/actual file remains as it is ##

ls -l /root/home/httpd/test1.com/index.php 


How to create Symlink to a directory?

To create a symlink to a directory, simply execute the following command;

ln -s {source-dir-name} {symbolic-dir-name}


For instance, if you want to create a symbolic link from the /home/lighttpd/http/users/user/php/app/ directory to the /app/ directory, then the command to run is shown below;

ln -s /home/lighttpd/http/users/user/php/app/ /app/


So i can modify files using /app/ with the commands below as shown here;

cd /app/
ls -l
vi config.php


How to overwrite symlinks/Soft link?

To overwrite symbolic links, simply pass the "-f" to the ln command to overwrite links as shown below;

ln -f -s /path/to/my-sym-file.txt link.txt

How to delete or remove symlinks/soft links?

You can use the rm command to delete symlinks files. For example, take a look at the command below;

rm my-link-name
unlink /app/
rm /home/user/index.php


How to get help about the ln command?

To get help about the ln command by running the following command;

man ln
ln --help


This command will list all the functions which the ln command can use.

[Need urgent support in Installing Software on your CentOS Server? We are available to help you today.]


Conclusion