Unix Tip — Recursively grep’ing a Directory Structure

For those of you who are keeping track of my adventures at work dealing with getting PMS to communicate with TOUCH.  (I swear I’m not making these names up.  There’s also components called COORS and BS.)  TOUCH was created around 25 years ago and has stood the test of time but still needs tweaked every now and then.  The directory structure has directory upon directory.  The code is not integrated into any nice IDE and I haven’t had the time to do anything special with it to make it nice and easy to find stuff with.  Function and datatype names are random, so I constantly have to root around for where things are defined.  With the recursive directory structure not being consistent, I can’t just do something like grep “XXX” */* to find something so I had to come up with something a little sexier.  I found this little gem on the internet and it lets you walk through a directory structure of your choice and look for every occurence of a string recursively.  If you’ve seen it or know it, great but I thought it was a rather nice way of doing things:

find . -exec grep “<your search string>” ‘{}’ \; -print
I’d suggest piping this to more so that you don’t just get a blizzard of unreadable results.  Have fun!

One Comment

Tom  on June 13th, 2009

wow. recursion. I am sitting here thinking about what you told me back half a lifetime ago (half your lifetime, not mine), and grinning.

Leave a Comment

You must be logged in to post a comment.