Quickly find any text string in any set of files

Nov 05, '00 09:42:42PM

Contributed by: robg

To quickly find any text string within any text file, try this from a terminal window:

grep -l  [text to find] [files to look in]
For example, grep -l 123abc *.html will list the name of any file in the current directory that ends in .html and contains the string 123abc.

(That's a lower-case-L following the GREP)

Quite powerful, and fairly fast. Now, if you have some spare time, and want to see what it can really do, try this:
su root
cd /
grep -lr "text to find" *
This will tell the OS to find the "text to find" in every file in every directory, all the way down through the tree. The -r flag tells grep to recursively search directories.

Of course, OS X has something like 26,000 files, so this can take a very long time!

Comments (3)

Mac OS X Hints