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…
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.
Protip: did you know you use grep on Windows? This comes in handy for forensic log parsing and analysis on Windows Server IIS.
My name is Jan. I am not a hacker, coder, developer or guru. I am merely a systems administrator, doing my daily thing at Vevida.
If you feel a post has helped solve your problem, or has saved you time, please consider making a donation. You can transfer a direct donation through Paypal or via bank wire-transfer IBAN: NL31 ABNA 0432217258 (Jan Reilink). Thanks!