本文介绍了错误:"grep:参数列表过长";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下命令,但出现参数太长错误.你能帮忙吗?.

I am trying to run the following command, but gets argument too long error. Can you help?.

HOST# grep -rl 'pattern' /home/*/public_html/*
-bash: /bin/grep: Argument list too long

有没有一种方法可以覆盖此错误,并在所有用户的public_html目录中grep我想要的模式匹配文件.同一台服务器中大约有500多个用户.

Is there a way to override this error and grep the pattern matching files I want in all users public_html directory. There are around 500+ users in the same server.

推荐答案

使用find

find /home/*/public_html -type f -exec grep -l 'pattern' {} +

+修饰符使其可以按可管理的块将文件名分组.

The + modifier makes it group the filenames in manageable chunks.

但是,您可以使用grep -r来实现.此参数应为目录名称,而不是文件名.

However, you can do it with grep -r. The arguments to this should be the directory names, not filenames.

grep -rl 'pattern' /home/*/public_html

这将只有500多个参数,而不是数千个文件名.

This will just have 500+ arguments, not thousands of filenames.

这篇关于错误:"grep:参数列表过长";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:38