Find text in Files recursively on Linux and Mac OS X

Ever had a page that says something like “Test” on it, and you have no idea where that page is? I know you have and that’s why you’re here. You’ve thought to yourself “If I could just search to find the text in files recursively it would make my life so much easier!” and it does.

I’ll give you an example. Recently I was working on a Drupal project using advanced forum and I had this ridiculous block “What’s going on?” below my forum and I didn’t want it there. Going through file by file wasn’t exactly what I envisioned my day to be so I started looking around for a simpler way to find text in files using linux but I wanted it to work on Mac OS X too because I run production on Linux and Development on Mac OS X.

The baby-making-magic time-vampire killing power is below

grep -lir "some text" *
// or
find /path -name *.txt | grep -lir "some text" *

Sample output

bmaxwell$ grep -lir "What's going on" *
./modules/advanced_forum/styles/naked/.svn/text-base/advf-forum-statistics.tpl.php.svn-base
./modules/advanced_forum/styles/naked/advf-forum-statistics.tpl.php

Obviously the first one is the svn base file for that revision so we can ignore it. The second asshole causing all of the trouble known to man-kind contains exactly what I’m trying to find so I can use my DELETE button, or modify it.

Tetco rewards cards are bullshit.
Bryan

Related reading

  • No Related Post

Leave a Reply