我有一个文件列表,cache_temp.
在文件cache_temp中:
/home/maildir/mydomain.com/een/new/1491397868.M395935P76076.nm1.mydomain.com,S=1740,W=1777 /home/maildir/mydomain.com/een/new/1485873821.M199286P14170.nm1.mydomain.com,S=440734,W=446889 /home/maildir/mydomain.com/td.pr/cur/1491397869.M704928P76257.nm1.mydomain.com,S=1742,W=1779:2,Sb /home/maildir/mydomain.com/td.pr/cur/1501571359.M552218P73116.nm1.mydomain.com,S=1687,W=1719:2,Sa /home/maildir/mydomain.com/td.pr/cur/1498562257.M153946P22434.nm1.mydomain.com,S=1684,W=1717:2,Sb
#!/bin/bash for i in `grep -v ^# ~/cache_temp | grep -v "dovecot.index.cache"`; do if [ -f "$i" ]; then size=$(du -sh "$i" | awk '{print $1}') echo $size fi done
我有一个文件大小列表:
4,0K 4,0K 432K 4,0K
我该如何计算它们的总和?
使用stat而不是du:
原文链接:/bash/385881.html#!/bin/bash for i in `grep -v ^# ~/cache_temp | grep -v "dovecot.index.cache"`; do [ -f "$i" ] && totalsize=$[totalsize + $(stat -c "%s" "$i")] done echo totalsize: $totalsize bytes