grep: unknown directories method

The title of the post is the error message I got when attempting to grep a directory containing a file whose name started with a hyphen ( – ).

What has happened is that grep interprets hypens as switches, as if the idea was to convey options to use. This gave me a problem as I realised the file shouldn’t have been placed there in the first place and subversion was unable to remove it.

The Double-Hyphen Trick

The resolution is to pass two hyphens to the command, I didn’t know this before but this means “enough of the options, here’s the list to operate on”, or words to that effect. I used them to remove the file in question


svn rm -- \-*

Hopefully I’ll remember to look here next time I see this error message … but maybe not. So long as I don’t find myself on Google again

5 thoughts on “grep: unknown directories method

  1. Geoff: Actually no. This is my blog and I'll post what I like, I consider the code snippet to be an entirely useful and appropriate form of recording information and it suits me to use it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">