How to remove symbolic link
Matthew Barrera
I was trying to create this symbolic link:
sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadminbut I accidentally typed:
sudo ln -s /usr/share/php,yad,in /var/www/phpmyadminSo now I want to correct it but it says symbolic link already exist.
16 Answers
You can use rm to delete the symlink.
Example:
-rw-rw-r-- 1 2014-01-02 09:21 tmo
lrwxrwxrwx 1 2014-01-02 09:21 tmo2 -> tmoThen ...
rm tmo2will remove the symlink.
8You can try the unlink command as well.
unlink is a similar command to rm. Therefore rm <symlink> will work same as unlink <symlink>
Here is the man page.
2Suppose you were trying to do:
sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin/but accidentally did:
sudo ln -s /usr/share/somethingelse /var/www/phpmyadmin/To correct it simply navigate to the folder where the link is and unlink
cd /var/www/phpmyadmin/
~:# unlink somethingelse 0 You can use the following to remove the symbolic link
sudo rm /usr/share/php,yad,inExplanation
rmis the terminal command to remove a file. Seerm --helpfor more options that it can take.sudois used because the symbolic link was created withsudo. The file therefore belongs to root and your normal user will not have permission to edit/remove it (you would be able to force this if you had write permission on the directory, which would not be the case here).
Extra
Also see this post and my comment to the first answer to access phpmyadmin when getting a not found error after install.
0A small caveat I found was that I was trying to run rm and unlink on a symlink and I was getting an error that it was a directory.
$ rm folder_name/
rm: cannot remove ‘folder_name/’: Is a directory
$ unlink folder_name/
unlink: cannot unlink ‘folder_name/’: Not a directoryTo remove the symlink, I used unlink folder_name. It was failing as there was a trailing / which causes the file to appear to be a directory.
I stumbled here because I had to remove a dpkg-divert and the new package won't install until it was removed.
So if you have done something like this:
sudo dpkg-divert --add --rename --divert /usr/bin/gcc.real /usr/bin/gccYou need to remove it with something like this:
sudo dpkg-divert --remove /usr/bin/gcc.real