Reputation: 85
Looking for solaris command for getting list of all files containing search pattern (recursively). I know how to do it for linux but same command is not working in solaris:
bash-3.2# uname -a
SunOS D1NCIC-CL01 5.10 Generic_148888-03 sun4u sparc SUNW,Sun-Fire-15000
bash-3.2# find . -type f -print0 | xargs -0 grep -l "contentInFile"
xargs: illegal option -- 0
xargs: Usage: xargs: [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] [-i[replstr]] [-L #] [-l[#]] [-n # [-x]] [-s size] [cmd [args ...]]
find: bad option -print0
find: [-H | -L] path-list predicate-list
Upvotes: 1
Views: 26087
Reputation: 30823
As is so often the case when combined with find
, xargs
is useless here. You can run this portable command on both Solaris and Linux to get what you want:
find . -type f -exec grep -l "contentInFile" {} +
Upvotes: 7
Reputation: 31087
If your filenames don't contain any whitespace, simply use -print
and omit the -0
from xargs
.
If they do, upgrade to Solaris 11, and use /usr/gnu/bin/find
and /usr/gnu/bin/xargs
(GNU Tools out of the box in Solaris 11).
Alternatively, if you're stuck on Solaris 10, install the GNU Find Utilities (How do I grep recursively?), or one of the alternative search tools suggested in How do I grep recursively? (Ag
, ack
).
Upvotes: 1