18

Possible Duplicate:
How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)?

Like an idiot, I ran this command:

 tar -cf -X awstats-icon icon tarfile.tar . 

I was trying to use the -X switch to exclude awstats-icon and icon directories.

Now I have a large file named -X and I cannot seem to delete it. I tried using:

 rm -X rm `-X` rm '-X' 

However none of these have worked. Any suggestions?

1
  • 3
    Like an idiot, I ran this command: ... you're not an idiot, it's just that tar is old-fashioned. Commented Jan 9, 2012 at 21:50

2 Answers 2

43

Try rm ./-X from the folder that "-X" resides in.

1
  • 4
    This solution will work even when the individual command doesn't support the -- trick. Commented Jan 9, 2012 at 20:52
40

You can use -- on a shell command to make it clear that options have ended, this should therefore work: rm -- -X

2
  • 10
    Good answer, but readers should note that -- is only supported by the GNU tools. Don't expect it to work on BSD. Commented Jan 9, 2012 at 21:23
  • 1
    To reiterate what Zan said, -- is not a shell feature, it's a feature of rm and many other GNU tools. Not all tools support it, so Tim's answer is more portable, across Unix systems and across utilities. Commented Jan 12, 2012 at 18:20