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
I think you’ll find this is a feature of the getopt library, and so is part of all your favourite Gnu tools.
Geoff: Pleased to see you are enhancing my blog posts to the level of encyclopaedia entries as usual :) Thanks for your comment.
No doubt you’re regretting choosing to have a blog instead of a Wiki!
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.
Thanks! I put in a trackback here: http://www.westwideweb.com/wp/2008/11/14/grep-unknown-directories-method/
This helped me out of a jam today, thanks again,
MXWest
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]
This is such a useful example for a common problem, thankyou!
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.
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