Ubuntu: How to remove symbolic link


I was trying to create this symbolic link:

sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin  

but I accidentally typed:

sudo ln -s /usr/share/php,yad,in /var/www/phpmyadmin  

So now I want to correct it but it says symbolic link already exist.


You can use rm to delete the symlink.


-rw-rw-r-- 1 2014-01-02 09:21 tmo  lrwxrwxrwx 1 2014-01-02 09:21 tmo2 -> tmo  

Then ...

 rm tmo2  

will remove the symlink.


You can try unlink command as well.
unlink is a alias command of rm. therefore rm <symlink> will work same as unlink <symlink>

Here is the reference link.


unlink /etc/alternatives/x-cursor-theme  

You may also be interested in update-alternates

update-alternatives --config x-cursor-theme  


You will use the following to remove the symbolic link

sudo rm path/to/the/link  


  • rm is the terminal command to remove a file. See rm --help for more options that it can take.
  • sudo is used because the symbolic link was created with sudo. The file therefore belongs to root and your normal user will not be able to edit/remove it since it has less 'power' than root.
  • path/to/the/link will be /usr/share/php,yad,in based on your comment.


Also see this post and my comment to the first answer to access phpmyadmin when getting a not found error after install.


Suppose 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  


I stubled here becuase 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/gcc  

You need to remove it with something like this:

sudo dpkg-divert --remove /usr/bin/gcc.real  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »