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?

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

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

  • 4
    This solution will work even when the individual command doesn't support the -- trick. – benzado Jan 9 '12 at 20:52

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

  • 10
    Good answer, but readers should note that -- is only supported by the GNU tools. Don't expect it to work on BSD. – Zan Lynx Jan 9 '12 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. – Flimm Jan 12 '12 at 18:20