Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


Create of Delete Symbolic Link in Linux and Nginx Server

# Create Symbolic Link - Syntax

# Example
ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

The above command will create a soft link of the file /etc/nginx/sites-available/ at /etc/nginx/sites-enabled/ so that the file can also be accessed using the path /etc/nginx/sites-enabled/ in this way, we can create a symbolic link without duplicating the file content. We can also create symbolic links for a directory following the same steps.

We can also test whether the file is actual file or symlink as shown below.

# Test symlink
ls -l <file path>

# Example
ls -l /etc/nginx/sites-enabled/

# Output
lrwxrwxrwx 1 root root 39 Oct  2 15:16 /etc/nginx/sites-enabled/ -> /etc/nginx/sites-available/

# Test regular file
ls -l /etc/nginx/sites-available/

# Output
-rw-r--r-- 1 root root 1092 Oct  2 15:23 /etc/nginx/sites-available/

With the above output, we can clearly distinguish whether the file path is a soft link or actual file.

We can remove the soft link by simply deleting it like we delete a normal file. We can also use the command unlink to remove a symlink as shown below. Make sure to perform the symbolic link test before deleting it to ensure that you are not deleting the actual file.

# Delete Symbolic Link
sudo rm /etc/nginx/sites-enabled/

# Remove Symbolic Link
sudo unlink /etc/nginx/sites-enabled/

Both the commands delete the symbolic link without deleting the actual file. We can see that we have used the regular command rm to delete the symbolic link.

create_delete_symbolic_link_linux.txt · Last modified: 2020/06/19 05:26 by wikiadmin