2

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?

2 Answers 2

2
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.

1
  • 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, 2012 at 16:40
0

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 {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .