Counting

In the beginning I used TOTAL=`ls /d2lmig/*/*/bak/*/* | wc -l` to get a total count. All was good.

Until at around 55,000 files I got: -bash: /bin/ls: Argument list too long.

Then I used TOTAL=`find /d2lmig/*/*/bak/*/* -name *.bak | wc -l` to get a total count. All was good.

Until at around 90,000 files I got: -bash: /usr/bin/find: Argument list too long.

It happened that I was already using a for do done loop and getting a count for each bak directory. So I added within the for loop:

TOTAL=`expr $TOTAL + $COUNT`
if [ $RUNTYPE = “INTERNAL” ] ; then echo ” Running total = $TOTAL” ; fi

(INTERNAL is a value I pass at the command line that controls whether the email is sent to me or other parties.)

Comment out the TOTAL using find. Voila.

I know, I should have done it this way in the beginning. Sloppy code to go back and get the total. Maybe because I have this post here, I reference it and not be so bad in the future.

from Rants, Raves, and Rhetoric v4

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s