Error: “grep: Argument list too long” [duplicate]

随声附和 提交于 2020-01-22 07:36:24

问题


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

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.


回答1:


Use find

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

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

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

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



来源:https://stackoverflow.com/questions/29727135/error-grep-argument-list-too-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!