The grep utility that is included with Solaris 10 does not appear to support recursive behaviour, unlike many flavours of Linux which do so using the -r switch. Until recently I had been using something like:
$ grep 'somestring' `find . -name '*'`
in an attempt to emulate a recursive grep but this doesn’t work too well when you run it from a high-level directory on your system (the size of the output from the find becomes too large for grep to handle).
However, I recently found a much better alternative:
$ find . | xargs grep 'somestring'
This is shorter and much easier to remember, although from initial observations, it seems to take a little longer to run but I can live with that since it works.
Thank YOU!! I have been looking all over for a simple description of a recursive grep I could use. It worked GREAT!!
I used the following on SunOS 5.9 and got exactly what I needed. Thank you thank you. So many web sites did not have a simple, straightforward cmd.
find . | xargs grep -li ‘diana’
Agreed with Diana. Thank you SO much for this post! Couldn’t find it so simply anywhere else! Have it bookmarked for sure.
thank you for sharing such a useful command
Great discovery! I had looked for a while to find a recursive grep for solaris and your example of using find with xargs works wonderfully. Much thanks!
thanks for this… 🙂
xargs is an enemy in disguise if you at a later date get files with “interesting” names:
touch important_file
touch ‘not important_file’
ls not* | xargs rm
mkdir -p ’12” records’
ls | xargs rmdir
Parallel does not cause these issues. http://parallel.nongnu.org
Thanks for this, though if solaris did not suck so much we wouldn’t need it.
It’s the end of 2012 and this is still helpful. You saved me a lot of time.
Bless you for sharing this command! It’s 2013, we’re still using SunOS 5.8 in places, and this syntax is still useful!
God bless you. Came handy many times.
Good job!
Greet from Poland.
Ohhh thank you so much!