| Subcribe via RSS

using find plus xargs with whitespace

April 21st, 2010 | No Comments | Posted in Uncategorized

Often I find myself needing to search the filesystem or a particular directory for anything containing a certain phrase.
This was done by find . | xargs grep “phrase”
However if a file or directory contained a space or any other whitespace in the name it would barf.

An easy way to overcome this is to run find like this:
find . -print0 | xargs -0 grep “phrase”

What this does is tells find to print the path to the file and terminate it with a NULL character. Then “-0″ tells xargs to split arguments on NULL instead of whitespace.