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
1
|
|
Unfortunately, on OSX this is not robust to spaces or quotes in filenames. Thus if you have a filename like
1
|
|
in your search path the typical find | xargs | grep
invocation will terminate with the error
1
|
|
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 -I{}
with xargs
and grep
to surround the filename with quotes doesn’t fix this.
1
|
|
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.
1
|
|
and it works!