Reputation: 5
I have created a shell script that would read a text file and will find the size of the file. The problem is its not giving the total file size.
For example when I execute ./sushant7.sh
I get:
Size is 4.0K lesurvey1
Size is 4.0K tbbsr11d1def
Size is 4.0K tbbsr11d1def
I want to get 12k
as total which I am not able to.
My script is
FILE1=/home/dev/sushanttest
cd $FILE1
while read file
do
echo "Size is ` du -ha $file`"
done < /home/dev/sushanttest/listing.txt
Upvotes: 0
Views: 75
Reputation: 10502
Perhaps you could make use of the -b
switch as well to du
to print out the size in bytes. For example:
$ du -cb FILE_GLOB | grep total | awk '{print $1}'
Upvotes: 0
Reputation: 14842
You can use this:
xargs du -ch < /home/dev/sushanttest/listing.txt | grep total
This gives all the files as an argument to a single du
call. If you iterate yourself over the files, you'll have to sum up yourself.
Upvotes: 3