The other day I was searching for a particular email file in an Maildir on one of our mail servers. Knowing only the From address, I thought I’d use grep. Unfortunately it failed and gave me an error: /bin/grep: Argument list too long. Here is how to overcome this grep error…

/bin/grep: Argument list too long

How to grep through a large number of files? For example:

grep -r "example\.com" *
-bash: /bin/grep: Argument list too long

Well, this was no wonder, since there are over 190500 files in that particular Maildir:

ls -1 | wc -l
190516

There are several ways of overcoming this error message. One, for instance is:

find . -type f | xargs grep "example\.com"

A second option to overcome the error is: substitute the “*” (asterisk) with a “.” (dot), like:

grep -r "example\.com" .

In newer versions of grep you can omit the “.“, as the current directory is implied.

This may interest you:   New Open-Xchange merger: PowerDNS