質問

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?

役に立ちましたか?

解決

You may try like this:

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top