Linux Remove Symbolic Link (Symlink)
In this tutorial, we are going to learn how to remove symbolic links (soft link or symlink) in Linux using the command-line interface.
A symbolic link in the Linux operating system is nothing but a shortcut to another file. Therefore, a Linux admin can delete a symbolic link using the
rm command only removes the symbolic link and the original file is untouched.
There is another command, the
unlink command, which we can use to remove symbolic links in Linux.
Example: Delete Symbolic Link
In our Ubuntu server, inside the
/etc/apache2/sites-enabled directory, we have a symlink called
000-default.conf, which points to the
Now, if I want, I can remove this link using the
rm command as follows:
Now, if I run the
ls command, the symlink no longer exists. However, the original file still exists in the
If we use the
rm command with the
-i option, it will ask for confirmation before deleting the symbolic link:
rm -i 000-default.conf
Type "yes" or "y" to confirm that you want to remove the symbolic link. The
unlink command, however, does not have a prompt option.
How to Remove Symlink Directory in Linux
unlink commands can be used to delete a symlink that points to a directory. However, do not use forward-slash (/) at the end of the link name. A Linux admin can delete Symlink Directory as follows:
If a forward-slash (/) is used, the rm command will delete files inside the target folder, not the symlink directory.