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?

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

2 Answers2

43

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

Tim
  • 6,113
  • 1
  • 18
  • 19
40

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

dtech
  • 987
  • 2
  • 9
  • 14
  • 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 09 '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