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.

I made a symbolic link with the following commmand:

ln -s ../test5

I want to remove it now but my rm fails:

$ rm -Rf test5/
rm: cannot remove `test5/': Not a directory
$ rm test5/
rm: cannot remove directory `test5/': Is a directory
$ rmdir test5/
rmdir: test5/: Not a directory
$rm -r test5/
rm: cannot remove `test5/': Not a directory

$ls -l
 0 lrwxrwxrwx  1 peter peter    8 Jul 20 15:30 test5 -> ../test5/

How can I remove my symbolic link? (Ubuntu 8.10, bash)

share|improve this question
add comment

4 Answers 4

up vote 52 down vote accepted

Remove the trailing slash:

With prompt:

$ rm test5

Without prompt:

$ rm -f test5

share|improve this answer
add comment

Try rm test5
(without the training slash).

The slash indicates that 'test5' is a direactory whereas it's actually a file linking to a directory.

share|improve this answer
add comment

You can run removing the trailing slash:

$ rm test5

This will remove the file (i.e. the symlink).

Alternatively you may use unlink:

$ unlink test5

Again you must omit the trailing slash since you are attempting to unlink the symlink not the directory.

share|improve this answer
2  
Why the -Rf ? –  Arjan Jul 20 '09 at 13:14
add comment

I feel silly asking, but have you tried rm -r? Since it's a symbolic link it shouldn't delete the target.

Edit: Just tried it, it's correct

Edit 2: rmdir says in its first line of the man page it deletes empty directories. I would think because it's a link it had the directory bit checked on its file properties, but because rmdir doesn't suspect that being the case it spits errors. Just use rm -r

share|improve this answer
1  
This will ask me to delete the files in the directory, that's not what I want, I want to delete only the link –  Peter Smit Jul 20 '09 at 12:46
    
The asking was because interactive was defined in my .profile. Added the response to rm -r. It still doesn't work. –  Peter Smit Jul 20 '09 at 12:50
    
You left the trailing '/' that's why it failed –  bobby Jul 20 '09 at 12:52
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.