在所有搜索文件中搜索字符串会出现 /bin/grep: Argument list too long 错误

在所有搜索文件中搜索字符串会出现 /bin/grep: Argument list too long 错误

我尝试使用以下命令在所有文件中搜索用户/var

sudo find . -type f | xargs sudo grep 202007602 | tee /tmp/202007602.log

输出:

grep: ./www/html/jenkins/workspace/node_modules/xpath/docs/xpath: No such file or directory
grep: methods.md: No such file or directory
grep: ./www/html/jenkins/workspace/Efendibey-Live/node_modules/xpath/docs/function: No such file or directory
grep: resolvers.md: No such file or directory
sudo: unable to execute /bin/grep: Argument list too long
sudo: unable to execute /bin/grep: Argument list too long

然后,我尝试了 stackoverflow 的解决方案,但这也不起作用,并且出现以下错误:

sudo find /var -type f -exec sudo grep -l '202007602' {} + | tee /tmp/202007602.log
sudo: unable to execute /bin/grep: Argument list too long
sudo: unable to execute /bin/grep: Argument list too long
....
....

我用的是centos 7。

你能建议一下吗?

答案1

让 GNU用它的标志grep为你做这件事-r

sudo grep -r 202007602 /var | tee /tmp/202007602.log

相关内容