开发者

shell script: recursively find a file with a keyword

开发者 https://www.devze.com 2023-01-04 12:14 出处:网络
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

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开发者_开发百科.


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)


I use something like:

find r_dir -type f -exec grep "key_word" {} \; -print
0

精彩评论

暂无评论...
验证码 换一张
取 消