How to remove a symbolic link to a directory?

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)


Remove the trailing slash:

With prompt:

$ rm test5

Without prompt:

$ rm -f test5


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.


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.