Tuesday, December 2, 2008

revoming symbolic links

in my home debian i had no problems with revoming symbolic links, i just used rm and it worked fine. but tuday, on a centos server rm replied: cannot remove directory ‘xxx/’ : Is a directory

the solution i've found was using unlink xxx:

When using the rm or unlink command to remove a symbolic link to a directory, make sure you don’t end the target with a ‘/’ character because it will create an error. Example:
$ mkdir dirfoo
$ ln -s dirfoo lnfoo
$ rm lnfoo/
rm cannot remove directory ‘lnfoo/’ : Is a directory
$ unlink lnfoo/
unlink: cannot unlink ‘lnfoo/’: Not a directory
$ unlink lnfoo
$
Notice how one complains it “Is a directory”, but the other complains it is “Not a directory”, which I found confusing. This is a problem if you have a tendency to use tab completion a lot, because it will stick a ‘/’ at the end.

thnx, Karl

0 comments:

Post a Comment