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?

  • 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

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

cat -- -w
rm -f -- -w

Prefix it with the path. For instance:

cat /home/whatever/-w
rm /home/whatever/-w
  • 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

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