Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally created a link to a folder in the same directory with the same name as the folder, and I'm not sure how to safely remove it without removing the actual folder.

# ls -l
total 4
lrwxrwxrwx 1 root root   26 Oct  8 19:36 monbodb-linux-x86_64-2.0.2 -> monbodb-linux-x86_64-2.0.2
lrwxrwxrwx 1 root root   27 May 23 14:58 mongo -> mongodb-linux-x86_64-2.0.2/
drwxr-xr-x 4 root root 4096 Oct  8 19:37 mongodb-linux-x86_64-2.0.2

If I try to unlink, I get the following, which is why I'm concerned about trying to rm it:

# unlink mongodb-linux-x86_64-2.0.2
unlink: cannot unlink `mongodb-linux-x86_64-2.0.2': Is a directory

How can I specify the symbolic link so that I only delete it and not the folder?

share|improve this question
up vote 1 down vote accepted
unlink monbodb-linux-x86_64-2.0.2

You're trying to unlink the actual directory, not the symlink. They have different names – it's impossible to have two items with identical names in the same directory.

share|improve this answer
Even after reading your response, it took me a minute to see the typo. Thanks for pointing that out, I completely missed the difference. – Brendan Oct 9 '12 at 16:40

Usually for this, you can use the inode number, which will be guaranteed to be unique.

ls -iF

(get inode number of the symlink, say 123456)

find . -inum 123456 -exec rm -i {} \;
share|improve this answer

Your Answer


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.