Config Server Firewall

Linux Remove Symbolic Link (Symlink)

Linux Remove Symbolic Link

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:

rm symbolic_link

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.

unlink symbolic_link

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 /etc/apache2/sites-available/000-default.conf.

Example: Delete Symbolic Link

Now, if I want, I can remove this link using the rm command as follows:

rm 000-default.conf

Now, if I run the ls command, the symlink no longer exists. However, the original file still exists in the /etc/apache2/sites-available/ directory.

delete symbolic link linux

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.

remove symlink linux

The rm and 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:

rm symlink_directory

If a forward-slash (/) is used, the rm command will delete files inside the target folder, not the symlink directory.