3

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?

Given92
  • 101
  • 2
  • 8

6 Answers6

1

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

Ask and Learn
  • 8,661
  • 8
  • 37
  • 43
1

You may try like this:

rm ./-foo
rm ./-filename
rm -- -foo
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

use unlink command:
unlink -a...

Soosh
  • 812
  • 1
  • 8
  • 24
0

-- indicates the rest are arguments, not options.

rm -- -a

shx2
  • 61,779
  • 13
  • 130
  • 153
0

You can still get away with rm by saying:

rm ./-a

Sergo Pasoevi
  • 2,833
  • 3
  • 27
  • 41
0

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.

Jim Stewart
  • 16,964
  • 5
  • 69
  • 89