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 "--"?

Due to mismatched switches when I was trying to run a command, I have a log file named -w in a directory. I want to see its contents with cat (or less) and then delete it.

I've tried escaping it with backslashes, single-quotes, double-quotes, parentheses, and backticks, but cat always complains that w is an unknown option.

How can I properly reference this file?

share|improve this question

marked as duplicate by Gilles, Michael Mrozek Aug 12 '11 at 14:18

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.

    
I would merge, but all the answers are already on the other question –  Michael Mrozek Aug 12 '11 at 14:19
    
@Michael: The other thread is much less concise than this one. The redirection should have been the other way around :-p –  Stéphane Gimenez Aug 12 '11 at 14:37
    
@Stephane Typically you close newer questions as duplicates of older ones, unless the older one was completely terrible –  Michael Mrozek Aug 12 '11 at 15:00

2 Answers 2

Prefix it with the path. For instance:

cat /home/whatever/-w
rm /home/whatever/-w
share|improve this answer
3  
Nice trick that works when parameters are filenames. One may use ./-w also. –  Stéphane Gimenez Aug 12 '11 at 13:34
    
@Stéphane: right, ./ also suffices! –  nico Aug 12 '11 at 13:37

Almost all commands allow -- as separator between options parameters and positional parameters. You can use the following:

cat -- -w
rm -f -- -w
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.