Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 professional 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.

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

2 Answers 2

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

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

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