Operating System - Linux
1823415 Members
2432 Online
109655 Solutions
New Discussion юеВ

Scripting - /bin/grep: Argument list too long

 
Geoff Wild
Honored Contributor

Scripting - /bin/grep: Argument list too long

Okay - go easy - just got back from Cabo San Lucas - so I'm not quite with it...

Anyway - being postmaster, I had a to of email - 38,458 to be exact in my little inbox....

I use Sendmai with Maildirs...

So, I tried this:

cd /var/mail/met.ca/gjwild/Maildir/cur
for i in `grep "To: postmaster" \`ls -l|grep "Nov" | awk '{print $9}'\` | awk -F:To '{print $1}'`; do rm -f $i; done

Unfortunately, I get:
/bin/grep: Argument list too long

So I tried

grep "Nov 11"

still no go...

So I had to reduce further:

grep "Nov 11 01"

That works...but that means I have to run it for everey hour for every day - there has got ot be a better way.

Thanks...Geoff





Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
3 REPLIES 3
Hein van den Heuvel
Honored Contributor

Re: Scripting - /bin/grep: Argument list too long


Hi there Geoff, how are you my friend!

This is a relatively often heard (hurt ;-) problem.
Checking it out on www.google.com/linux
Searching for "Argument list too long"
Gives about a thousand hits

The general solution is to use 'xargs'.

You could also try rebuild a kernel with a change to:

include/linux/binfmts.h
:
#define MAX_ARG_PAGES 32

make it 64? more still?

You failed to specify which Linux/version.
There may be specific solution for whatever you are running.
Be sure to read: http://www.linuxjournal.com/node/6060/print

Greetings from Nashua NH,
Hein.
Ivan Ferreira
Honored Contributor

Re: Scripting - /bin/grep: Argument list too long

You can use a pipe with the xargs command to solve the "argument list too long" issue.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Sandman!
Honored Contributor

Re: Scripting - /bin/grep: Argument list too long

Geoff,

xargs would be the way to go...man xargs(1) and look-up its "-n" option also.

cheers!