How can I grep for a string that begins with a dash/hyphen?

Mike picture Mike · Mar 11, 2010 · Viewed 122.8k times · Source

I want to grep for the string that starts with a dash/hyphen, like -X, in a file, but it's confusing this as a command line argument.

I've tried:

grep "-X"
grep \-X
grep '-X'

Answer

newacct picture newacct · Mar 11, 2010

Use:

grep -- -X

Related: What does a bare double dash mean? (thanks to nutty about natty).