Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining the total size of a list of files

Status
Not open for further replies.

costiles

Technical User
Jun 14, 2005
117
US
I have a list of files - 82000 file names in the file. I want to get a total byte count on these files. Anyone suggest a script that will allow me to total these 82000 record sizes?
 
Code:
for i in $(cat file_list)
do
  ls -l $i | awk '{ sum += $5 } ; END { print sum }'
done
 
Provided the file names are in file_list, one per line:

Code:
#!/bin/ksh

ts=0
while read fname
do
  size=$(wc -c < "$fname")
  ts=$((ts + size ))
done < file_list
 
I could get neither of these scripts to work - they would not sum the total - leaving me just with a list of the sizes.
 
Well, I did not echo the variable ts at the end of the script:

Code:
#!/bin/ksh

ts=0
while read fname
do
  size=$(wc -c < "$fname")
  ts=$((ts + size ))
done < file_list
echo $ts

Is that the problem?
 
why don't you give an example of your list that contains the files in question. How else can we give you an exact solution? We don't have any idea what your data looks like so we go off assumptions.
 
Thanks for your input! It was a simple list of files - and the scripts - both ave me the size of the file - I made an adjustment and was able to total the sizes. The main problem was that the list was too large to use xargs - passing a list to it - so bsically I made the same change that olded just submitted. Thanks for the input. Both worked - just with some minor adjustments. thanks for the input!
 
This is what I ended up doing. It totalled - and reported the total everytime it added another file.

#!/bin/ksh
ts=0
cat files.lst|while read fname
do
sum=`wc -c $fname|cut -c1-8`
ts=`expr $ts + $sum`
print $ts
done
 
This is actually the script that I ran.


#!/bin/ksh
ts=0
cat files.lst|while read fname
do
size=`wc -c $fname|cut -c1-8`
ts=`expr $ts + $size`
done
echo $ts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top