Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "grep: Argument list too long" [duplicate]

Tags:

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.

like image 354
John Avatar asked Apr 19 '15 07:04

John


People also ask

How do you grep If an argument list is too long?

/bin/grep: Argument list too long. A second option to overcome the error is: substitute the “ * ” (asterisk) with a “ . ” (dot), like: grep -r "example\.com" .

What is usr bin grep?

/usr/bin is the directory that is included in the search PATH. Therefore, which grep identifies the file as /usr/bin/grep .

What is grep in shell script?

In Linux and Unix Systems Grep, short for “global regular expression print”, is a command used in searching and matching text files contained in the regular expressions.


1 Answers

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.

like image 108
Barmar Avatar answered Sep 22 '22 06:09

Barmar