Removing a Symbolic Link to Directory on Linux

Written by James Mansson on December 12, 2012 Categories: Linux

Today I encountered one of those irritating gotchas that has a simple solution, once you know what the solution is.

I was working on a Linux server and wanted to remove a symbolic link to a directory. I tried:

rm linkname/

but this produced the error message:

rm: cannot remove `linkname/': Is a directory

After a few other tries, I did an online search, which revealed the solution. This is to run the command without the trailing slash (/):

rm linkname

The point is that is you including a trailing slash, the system thinks you want to delete a directory, whereas if you don’t, it thinks you mean a file. As the symbolic link is a file not a directory, even if it points to a directory as in this case, you need to use the slash-less form.

No Comments on Removing a Symbolic Link to Directory on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *