Shell实现统计文件列表的文件大小并累加

#!/bin/sh
sum=0
lineCount=0
homeDir="/home/imagemedia/ytsp/videoGSX/"
tempDir=""
tempResult=""
while read -r line
do
tempDir=${line#*//}
tempDir=${tempDir#*/}
tempDir=$homeDir$tempDir
tempResult=$(du -sh $tempDir)
size=${tempResult%M*}
let lineCount++
sum=`echo "$size + $sum"|bc`
echo $size
done<"/home/imagemedia/ytsp/log2.txt"

echo "$lineCount rows"
echo -n "$sum M"
echo

执行方式:bashxxx.sh

相关推荐