Add new comment

How to remove a file in unix with a leading dash in it's name?

That was the question I asked myself recently when I had a file called --exclude in the root of my filesystem. These commands all failed:

rm --exclude
rm "--exclude"
rm \-\-exclude
rm ??exclude

So I found the solution - so simple it embarrassed me. Just add the full path:

rm /--exclude

or tell the command line parser to stop interpreting options:

rm -- --exclude

Easy!

Blog Categories:

Back to top