I am entering a command I have done often with Linux, Unix perfectly fine but with Apple Mac OS X 10.8 (and probably before) I get a grep: unknown --devices option when I attempt to run the following command:

find . -type f -name '*.sql' 2>/dev/null | xargs grep -i 'texttolookfor'

I checked the results of the find command and they all appear to be just standard .sql files. And I should add that the problem occurs with other file searches not just .sql files. In searching the Apple site and Google I cannot seem to find any indication of what is going on here.

Does anyone have a suggestion?

3 Answers 3


It sounds like you've hit a file with a funny name, and xargs is treating it as two files. The best approach is to rework your find to deal with all names safely:

find . -type f -name '*.sql' -exec grep -i 'texttolookfor' '{}' +

This uses the find --exec COMMAND + syntax instead of xargs. You could also use -print0/xargs -0 (if that works on OS X, not sure), but there isn't really a reason to, unless you need other xargs features.

Finally, if OS X grep supports it, you can use -- to indicate end-of-options—it'd go before the '{}', above—though this really shouldn't be needed with find (since the found files always begin with ./)

  • 1
    Why are you quoting the +? It doesn't have any special meaning in the shell does it?
    – terdon
    Jan 10, 2014 at 18:13
  • @terdon 'I like "quote" marks', ‘they’ are 'fun' to "type". Or, more likely, for parallelism with ';' which does need to be quoted. Of course, I ought to use \; and \+ instead, as that's one less character... (edited to remove quotes)
    – derobert
    Jan 10, 2014 at 18:15
  • I figured that exec might solve it but I was not sure. It works well,
    – sldahlin
    Jan 10, 2014 at 20:35
  • Thanks for the end of options info! grep -- -D * worked great for grepping Java options in configuration files, on Mac, within current folder.
    – straville
    Aug 20, 2021 at 8:33

This sounds like you have the environment variable GREP_OPTIONS set. You can confirm with this command:

$ env | grep GREP_OPTIONS

If it's set you can simply unset it.


I'm not sure why this is done on OSX and there might be a better way to permanently disable it if it's getting annoying, but you could just add a line to your $HOME/.bashrc file, which should work, assuming this isn't set by something else after this file.

  • GREP_OPTIONS is not set
    – sldahlin
    Jan 10, 2014 at 20:36

Keep in mind that Macs are BSD-derived, not Linux-derived, so a lot of the tools you have in the terminal are the BSD, and not the GNU, flavors of the utility. BSD and GNU versions of things are largely interchangeable, but there are many differences which are subtle and quick to anger. Many of these subtleties arise in the text processing tools such as sed and grep; even tar has some issues that you need to keep in mind.

I would suggest looking into installing MacPorts, and using that to obtain the GNU versions of the utilities if you want your scripts to be compatible with a Mac.

  • I am aware of the subtle differences which can hammer you. The curious thing is the lack of documentation regarding the significance of the unknown --devices option
    – sldahlin
    Jan 10, 2014 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .