Find files containing a text under OSX or Linux

There are two methods I mainly use to find a text in multiple text files i.e. my project directory. If one is just generally looking for any file that may contain the text snippet I use grep:


grep -r "some_method_name" .

This will search all files recursively in your current path. If you only want to search in a sub directory from your current path just replace the dot with the path to the sub folder e.g.: grep -r "some_text" my/log/files

If I know or only want to see it for a certain type of file I’ll use find and xargs e.g. like this:


find . -name "*.erb" | xargs grep "some_method_name"

Again if you only want to search in a given sub directory just replace the dot with the path to the sub folder.

I found these two little bash lines real time savers!