这个问题在这里已经有了答案:
How to perform grep operation on all files in a directory?
(5 个回答)
去年关闭。
我的代码到现在为止。我是初学者。
count=0
for f in $ls do
count+= grep -c "classes" $f
done
echo $count
最佳答案
只需使用
grep -R <stringToSearch> <dirName>
例如在当前目录和里面的所有文件中搜索“文本”
grep -R "text" .
如果您想获得出现次数,请使用
wc -l
作为管道grep -R "text" . | wc -l
关于bash如何使用grep命令在给定目录中的所有文件中搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45801821/