Text Link Ads

Friday, September 28, 2007

Tip for the day: Recursive GREP on Solaris

Linux shells provide a recursive Grep function in the form of the -r switch.

Irritatingly, Solaris is supposed to be more advance but this same function in Solaris will have to be replicated using the piped command as follows:

/usr/bin/find . | /usr/bin/xargs /usr/bin/grep ‘Your Grep Value’

Or if your shell has all the right paths set, simply:

find . | xargs grep ‘Your Grep Value’

4 comments:

emoken said...

Thanks for your post Ive been looking for this! you save lots of my time!

greg c said...

Only problem I have is that on large directories, I get a lot of extraneous error messages on the directories that grep attempts to search.

Dave said...

/usr/bin/find .|/usr/bin/xargs /usr/bin/grep -s SearchString will suppress error messages

afraoucene said...

This will search in the result of find command which is the current directory files's Paths and not in their contents, so the correct command is :

find . -exec grep -i "SearchString" {} \;