The unix pattern for filtering files with a predicate then searching within them is
find | xargs | grep. For example, to search every file whose filename contains notes for a line containing mysql
Unfortunately, on OSX this is not robust to spaces or quotes in filenames. Thus if you have a filename like
in your search path the typical
find | xargs | grep invocation will terminate with the error
The first thing to know is you can use the
-t parameter in
xargs to at least tell you which filename it’s dying on, but that’s of limited use in making the command work. Even using
grep to surround the filename with quotes doesn’t fix this.
Many people must have run into this problem because there is a simple solution that all the tools understand: use nulls instead of newlines to delimit files.
and it works!