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.

  • 1
    permission denied. This is what i typed first: sudo ln -s /usr/share/php,yad,in /var/www/phpmyadmin – James Jan 3 '14 at 5:19
  • 6
    permission denied: You do know you need sudo if you want to use it in a situation you do not own the file? That goes for 'rm' too. – Rinzwind Jan 3 '14 at 6:32
  • 2
    i did it rm /usr/bin/python and removed my python from ubuntu :S – user433546 Jul 23 '16 at 19:17
  • 2
    @RaheelKhan no you did -not- You removed a SYMLINK. Python relies on this symlink though. If you recreate that symlink python will be back. – Rinzwind Jul 23 '16 at 19:29
  • 1
    I try this command but it seems that my file has been removed, I don't want to remove my file – saeed masoomi Dec 11 '17 at 15:52

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.

  • 9
    unlink has nothing to do with symlinks in particular. See serverfault.com/a/38817/64085 – Matthew Read Apr 15 '15 at 16:24
  • @kushvarma but it works. did you try that? – hakunami Jul 6 '15 at 9:25
  • 1
    the answer may be correct, but will confuse newbies – mit Jun 16 '18 at 15:26
  • "unlink is a alias command of rm" [Citation Needed] – mwfearnley Sep 16 at 15:44

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

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.

  • Your comment is not generic. Please always use generic command to show how to remove symbolic link – kushvarma Jul 4 '15 at 3:55
  • generic means, it should be valid for everything, like your command is specific for /usr/share/php,yad,in, but it should like rm <symlink> – kushvarma Jul 6 '15 at 12:15
  • @kushvarma, thanks. I've made the answer more generic - it was originally specific because the OP seemed to have an issue removing the file – chesedo Jul 6 '15 at 12:30

Sorry to necro post but I found this question when I was looking for an answer to this issue.

A 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 directory

To remove the symlink, I used unlink folder_name but it was failing if there was a trailing / for example unlink folder_name/ as it thinks it is a directory, not the file you want to remove.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.