A symbolic link is also known as symlink or soft link, is a special type of file that serves as a reference to another file or directory. A symlink can point to a file or a directory on the same or a different filesystem or partition. This guide explains how to remove symbolic links in Linux systems.
Before going ahead for removing symbolic link, make sure use have writing permission on parent directory of the symlink. Otherwise, you will get “Operation not permitted” error.
To check symlink and to find the destination directory or file, use
ls -l command.
ls -l /home/file.php
lrwxrwxrwx 1 tecnstuff tnsgrp 4 May 2 14:03 /home/file.php -> file_link.php
In above output the first character
l shows that the file is symlink and the arrow
-> symbol indicates where the symlink points to.
Remove Symbolic Links with rm
To remove a symbolic link, use the rm command followed by the symbolic link name. Using
rm command you can remove given file or directories.
For example, to delete the
/home/file.php symlink, you would run following command:
It will not show output and exits with zero.
If you would like to delete more than one symbolic link, you can pass multiple symlink names as arguments with
rm SYMLINK_NAME_1, SYMLINK_NAME_2
If you would like to prompt confirmation message before deleting the symlink, you should pass
-i option along with
rm -i SYMLINK_NAME
y and press
Enter key for confirmation.
You will get following output:
rm: remove symbolic link 'SYMLINK_NAME'?
Ensure that you never use
-r option along with
rm command while removing symlink. Otherwise it will remove all the contents of the destination directory.
Remove Symbolic Links with unlink
Unlink command removes the given symlink. It is possible to delete only a single file using
To remove a symlink using unlink, run the following command followed by the symlink name.
For instance, to remove the
/home/file.php symlink, you would run following
When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.
This tutorial shown you how to remove symbolic links or symlink using
If you have any question or feedback, please leave a comment below.