Linux: Recursively search through files for a pattern

I’ve been using a horrific monstrosity of a find command for this, and I just found out that grep can handle this by itself. Watch:

grep -rl 'your pattern' your_directory

For example, say you’re in the web root and you need to find every file which calls a certain function. You’d run:

grep -rl 'function_name' *

So easy. I’m so dumb.

By the way, the ‘-r’ makes it recursive and the ‘-l’ makes it just list the filename (instead of the filename and the context of the match).

Posted 10:06 AM | 2 Comments

Comments (Feed)

  1. Wow, I was looking for something just like this yesterday! Quite a coincidence really seeing as I randomly found your blog through the OSDB post :P

    Matt on
  2. @Matt: Ha, whatever works. Cheers!

    Mike on

WTF?