通过find文件并对大小求和统计目录大小

通过find文件并对大小求和统计目录大小(效果同du):

vi aa.sh

#!/bin/bash

Dir="/home/aa"

/bin/rm -rf /log/110Hudrm/110Huddu.txt
/bin/touch /log/110Hudrm/110Huddu.txt

for b in ls $Dir
do
if [ -d $Dir/$b ] && [ "$(ls -A $Dir/$b)" ];then
/usr/bin/find $Dir/$b/* -type f -exec ls -l {} \; | awk -F[:" "]+ '{print $5}' > /log/110Hudrm/110Huddu2.txt
Size=cat /log/110Hudrm/110Huddu2.txt | awk '{sum+=$1} END {print sum}'
echo $Size
si=$(($Size/1024/1024/1024))G
echo "$Dir/$b $si" >> /log/110Hudrm/110Huddu.txt
fi
done

:wq

转载于:https://blog.51cto.com/yangzhiming/2359438

你可能感兴趣的:(通过find文件并对大小求和统计目录大小)