Languages and Scripting
Showing results for
Do you mean

SOLVED
Highlighted

# Find results sum

Dear friends

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

# find . -name "fat*" -print

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

## 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:

> 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...

## 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.