How do you grep through code that lives in many different directories?

joeforker picture joeforker · May 14, 2009 · Viewed 10.2k times · Source

I'm working on a Python program that makes heavy use of eggs (Plone). That means there are 198 directories full of Python code I might want to search through while debugging. Is there a good way to search only the .py files in only those directories, avoiding unrelated code and large binary files?

Answer

Steve B. picture Steve B. · May 14, 2009
find DIRECTORY -name "*.py" | xargs grep PATTERN

By the way, since writing this, I have discovered ack, which is a much better solution.

(And since that edit, I have discovered ag).