Question

How can I delete a file whose name started with '-'?

For example, if I have a file named -a and I delete it with:

    rm -a

I will get:

    rm: invalid option -- 'a'
    Try 'rm --help' for more information.

So how can I do it?

Was it helpful?

Solution

You may try like this:

rm ./-foo
rm ./-filename
rm -- -foo

OTHER TIPS

rm "\-a" worked on my Mac, try again please

use unlink command:
unlink -a...

-- indicates the rest are arguments, not options.

rm -- -a

You can still get away with rm by saying:

rm ./-a

If you have GNU versions of rm or unlink, you can delete the file with:

rm -- -a

or

unlink -- -a

The -- tells it to stop processing command-line arguments and treat a leading - as a literal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top