Error: "grep: argument list is too long"

I try to run the following command but get an error too long. You can 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 pattern matching files that I want to use in all users_html directories. On one server about 500 users.

+4
source share
1 answer

Use find

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

The + modifier allows you to group file names in managed chunks.

However, you can do this with grep -r . The arguments for this should be directory names, not file names.

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

This will only contain 500 arguments, not thousands of file names.

+19
source

All Articles