How to find all files with a specific key word in a directory with subdirectories. For example, given a directory r_dir and subdirectoris d1, and d2, I need find all files contains "key_word" under r_dir and d1 and d2.
+1
A:
On Windows:
findstr /spin /c:"key_word" *.*
(s = recursive, p = ignore binaries, i = case-insensitive, n = line numbers)
On linux / OS X:
grep -i -r key_word *
(i = case-insensitive, r = recurse subdirs)
jeffamaphone
2010-06-18 18:05:23
coool! How to make the exact match? say, only "key_word" will be report but not "key_words".
Paul
2010-06-18 18:23:00
If you want key_word on its own on a line, then search for "^key_word$". If you want an exact match within a line, I can't find a way to do it so far without resorting to further greps.
chrisbtoo
2010-06-18 18:59:04
egrep -i -r "(\W|^)key_word($|\W)" *
chrisbtoo
2010-06-18 19:01:36
There is no `-r` option in POSIX `grep`.
Jörg W Mittag
2010-06-18 20:07:21
+1
A:
I use something like:
find r_dir -type f -exec grep "key_word" {} \; -print
chrisbtoo
2010-06-18 18:05:58