Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add file sizes

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I have this script ;
for dir in `find $STRT -type d -depth -print`
do NUM=`ls -la $dir | grep ^- | wc -l`
SIZ=`ls -la $dir | grep ^- | awk '{sum+=$5} END{print sum}`
echo $dir = $NUM files , $SIZ bytes
TOTN=`expr $TOTN + $NUM`
TOTS=`expr $TOTS + $SIZ`
done

It fails with this error ;
/sag/backups/Recycle = 153 files , 1.56302e+10 bytes
expr: 0402-046 A specified operator requires numeric parameters.
How do I get the awk to return size in integer (NOT scientific notation) ?
 
Use

{sum+=$5}END{printf("%15.0f\n",sum)}

where 15 is chosen to be larger than the maximum number of digits possible in sum

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
for dir in `find $STRT -type d -depth -print`
do
ls -la $dir|awk '/^-/{sum+=$5}END{printf "%.0f %.0f",NR,sum}'|read NUM SIZ
echo $dir = $NUM files , $SIZ bytes
TOTN=`expr $TOTN + $NUM`
TOTS=`expr $TOTS + $SIZ`
done


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top