BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Showing results for 
Search instead for 
Do you mean 

Find results sum

SOLVED
Go to Solution
Highlighted
Advisor

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
5 REPLIES
Trusted Contributor

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

Re: Find results sum

Thanks, John.

My results shows a bit strange number. like 5.97688e+07. What means "+" signal?
Acclaimed Contributor

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

Re: Find results sum

Thanks guys!
Honored Contributor

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.