====== Create or Delete Symbolic Link in Linux and Nginx Server====== [[https://linux.tutorials24x7.com/blog/create-or-delete-symbolic-link-in-linux]] ===== Create Symbolic Link ===== # Create Symbolic Link - Syntax ln -s [OPTIONS] FILE LINK # Example ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/mydomain.com The above command will create a soft link of the file /etc/nginx/sites-available/mydomain.com at /etc/nginx/sites-enabled/mydomain.com so that the file can also be accessed using the path /etc/nginx/sites-enabled/mydomain.com. 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 # Example ls -l /etc/nginx/sites-enabled/mydomain.com # Output lrwxrwxrwx 1 root root 39 Oct 2 15:16 /etc/nginx/sites-enabled/mydomain.com -> /etc/nginx/sites-available/mydomain.com # Test regular file ls -l /etc/nginx/sites-available/mydomain.com # Output -rw-r--r-- 1 root root 1092 Oct 2 15:23 /etc/nginx/sites-available/mydomain.com With the above output, we can clearly distinguish whether the file path is a soft link or actual file. ==== Remove Symbolic Link ==== 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/mydomain.com # Remove Symbolic Link sudo unlink /etc/nginx/sites-enabled/mydomain.com 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.