?
Solved

Total file size for one type of file.

Posted on 2004-11-05
7
Medium Priority
?
222 Views
Last Modified: 2013-12-15
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
0
Comment
Question by:jthenry
  • 4
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Luxana
ID: 12508759
find . -iname \*.gz -exec du -hc {} ';'
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12509507
#!/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
 
LVL 10

Accepted Solution

by:
Luxana earned 750 total points
ID: 12509636
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jthenry
ID: 12509793
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
 
LVL 10

Expert Comment

by:Luxana
ID: 12510026
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
 
LVL 7

Expert Comment

by:rugdog
ID: 12510937
find . -name \*.gz -ls|awk '{c+=$7} END { print c}'
0
 

Author Comment

by:jthenry
ID: 12525036
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question