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

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

  2. And if you’re piping commands, don’t forget it’s the actual command named in the error that needs the “–“:

    [code]$ find . | xargs grep selfip.b
    grep: unknown directories method
    $ find — . | xargs grep selfip.b
    grep: unknown directories method
    $ find . | xargs — grep selfip.b
    grep: unknown directories method
    $ find . | xargs grep — selfip.b
    (success)
    $
    [/code]

  3. Thanks. I could have struggled with this for a very long time, because it is surprising to me that my text inside of double quotes was being parsed as an option. Now I know! I’m already familiar with the double dash flag — from git, so now I know it applies to most unix tools.

  4. Thanks. I cothankyou!

    Reply ↓uld have struggled with this for a very long time, because it is surprising to me that my text inside of double quotes was being parsed as an option. Now I know! I’m already familiar with the double dash flag — from git, so now I know it applies to most

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.