Total file size for one type of file.

I need to find the total size of one type of file within a directoy recursively.

This is what I'm using but it's not giving me the correct total size.

find . -name *.gz -print|xargs du -hc

Can anyone think of another way to do it?

I'm on RH EL3.0

Thanks in advance
jthenryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LuxanaCommented:
find . -iname \*.gz -exec du -hc {} ';'
0
LuxanaCommented:
#!/bin/bash
for file in `find . -iname \*.gz -exec du -hck {} ';'| grep total | sed 's/total//'`
do {
total=`expr $total + $file`            
                       } done
mbtotal=$(echo "scale=2;  $total / 1024" | bc)
echo $mbtotal MB
0
LuxanaCommented:
to change path or file type just edit this bash script so for example searching for all *.conf files in /etc directory edit script like this:

 #!/bin/bash
for file in `find /etc -iname \*.conf -exec du -hck {} ';'| grep total | sed 's/total//'`
do {
total=`expr $total + $file`            
                       } done
mbtotal=$(echo "scale=2;  $total / 1024" | bc)
echo $mbtotal MB

----------
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jthenryAuthor Commented:
Thanks for the replies. But neither of these solutions give me a total from all directories. The results are much too small.

I don't know if this could be part of the problem but the folder has about 1TB of data and the total combined size of the searched files should be around 350GB.

Cheers.
0
LuxanaCommented:
to search whole directory tree on your filesystem you need to search in /

 #!/bin/bash
for file in `find / -iname \*.gz -exec du -hck {} ';'| grep total | sed 's/total//'`
do {
total=`expr $total + $file`            
                       } done
mbtotal=$(echo "scale=2;  $total / 1024" | bc)
echo $mbtotal MB

-------

first run command :

find / -iname \*.gz

this gives you list of all gz files in entire filesystem then edit script with desire find regural expresion all what script does is counting all file size for each file given by find / -iname \*.gz

0
rugdogCommented:
find . -name \*.gz -ls|awk '{c+=$7} END { print c}'
0
jthenryAuthor Commented:
It seems that I've got other problems with this server that may be interfering. But Luxana's script did work once for me. So I've accepted his answer.

Thanks to you both though.

Cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.