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

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


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).


grep -r -n "PATTERN" --include="*.py" DIRECTORY


I would strongly recommend ack, a grep substitute, "aimed at programmers with large trees of heterogeneous source code" (from the website)