Re: Find results sum (317 Views)
Reply
Advisor
Wagner_17
Posts: 25
Registered: ‎08-30-2004
Message 1 of 6 (317 Views)
Accepted Solution

Find results sum

Dear friends

I'm performing a search by some string. Like:

# find . -name "fat*" -print

./arq/0501/faturado46.0501
./arq/0501/faturado46.0503
./arq/0501/faturado46.0504
./arq/relat/1401/faturado46.1410
./arq/relat/1403/faturado11.1409

Now i need to know how is total size of files showed. Can someone help this no so smart soul? Thanks
Trusted Contributor
john123
Posts: 120
Registered: ‎02-28-2008
Message 2 of 6 (317 Views)

Re: Find results sum

Quick one..


find . -name "fat*" -type f -exec du -k {} \;|awk '{ sum += $1 } END { print sum }'

Out put will be in KB
regards
John
Advisor
Wagner_17
Posts: 25
Registered: ‎08-30-2004
Message 3 of 6 (317 Views)

Re: Find results sum

Thanks, John.

My results shows a bit strange number. like 5.97688e+07. What means "+" signal?
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 6 (317 Views)

Re: Find results sum

Hi Wagner:

You asked a question about using 'awk' and summing values, yesterday:

http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1293510

> 5.97688e+07. What means "+" signal?

This is scientific notation where "+07" means the number rasised to the seventh power of 10.

You can avoid this by using the floating format of 'printf' as I showed you in the aforementioned thread.

For your 'find' I might suggest:

# find . -type f -name "fat*" -exec ls -l {} \+|awk 'END{printf "%10.2f\n",SUM};{print $NF,$5;SUM+=$5}'

The use of the "+" delimiter to 'find' makes this very efficient. The use of the 'type -f' keeps the results limited to files and not directories, too!

Regards!

...JRF...


Advisor
Wagner_17
Posts: 25
Registered: ‎08-30-2004
Message 5 of 6 (317 Views)

Re: Find results sum

Thanks guys!
Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 6 of 6 (317 Views)

Re: Find results sum

> 5.97688e+07. What means "+" signal?
>
> This is scientific notation where "+07"
> means the number rasised to the seventh
> power of 10.

Actually, "e+07" means "times 10 to the
seventh power". The only number being raised
to a power is ten.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.