Safe way to remove a symbolic link to an non-existing directory (for the python binary)

22,537

Solution 1

you can simply remove the link with rm :

rm /usr/bin/python

Solution 2

You remove a symlink the same way you remove a regular file, even if it's a symlink to a directory. (If the target doesn't exist, it's a moot point whether it was intended to be a directory or a file.)

Share:
22,537
uploada
Author by

uploada

extropian in Tokyo

Updated on August 11, 2020

Comments

  • uploada
    uploada almost 4 years

    I accidentally typed:

    sudo ln -sf /usr/local/bin/python2.5/ /usr/bin/python 
    

    instead of:

    sudo ln -sf /usr/local/bin/python2.5 /usr/bin/python
    

    Now bash tells me that /usr/bin/python is not a directory whenever I run python.

    ls -l /usr/bin/python gives me expectedly /usr/bin/python --> /usr/local/bin/python2.5/
    

    Is there any safe way to remove that symbolic link to a directory (that does not exist) and replace it with a link to the intended file?

    Arigato in advance if you have any ideas.

    I am stuck....

  • uploada
    uploada over 13 years
    won't that remove the whole binary file?
  • uploada
    uploada over 13 years
    awesome it works. just was too scared about the action. realized that it was just a link.Tks
  • Keith Thompson
    Keith Thompson over 12 years
    @uploada: No, rm on a symlink just removes the symlink, not what it points to.