Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

While I was trying to compile a C shared object library, I accidentally created two symbolic links which point to each other. Is there a way to get rid of them without nuking the whole directory? I read that the only way to break a symbolic link is to delete the file it points to, but I'm sure there must be another way. Thanks for the help.

share|improve this question
2  
Then delete the file it po... oh god. How did you manage this? :P –  Phoshi Feb 2 '10 at 15:32
1  
It is easy to do, and even easier to fix. Simlinks point at a filename, and the target filename does not even have to exist. And rm removes the simlink, not the file it points to. –  Justin Smith Feb 2 '10 at 21:08
add comment

3 Answers

up vote 7 down vote accepted

It's not a problem to delete symbolic links. I'm not sure why you think that you need to delete the file the link points to.

Just delete them. Try this:

ln -s thing1 thing2   # thing1 does not exist
ln -s thing2 thing1   # circular reference
rm thing1 thing2      # no problem
share|improve this answer
add comment

Nevermind, I can delete both links simultaneously with rm. Why did someone say I had to delete the target file...

share|improve this answer
    
unlink is even nicer than rm to remove links safely. –  ℝaphink Feb 2 '10 at 16:21
1  
You could have even just deleted one of the simlinks and left the other - if you had any reason to. –  Justin Smith Feb 2 '10 at 21:07
add comment

When you delete a symbolic link in Linux, the link is deleted and not the target file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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