Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from serverfault.com Jan 9 '12 at 21:40

This question came from our site for system and network administrators.

marked as duplicate by Mat, Caleb, Michael Mrozek Jan 15 '12 at 18:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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.

share|improve this answer
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

share|improve this answer
Thank you, that worked great! – Charles Chadwick Jan 9 '12 at 18:15
Don't forget to accept the answer! – Xkeeper Jan 9 '12 at 20:25
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
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