linux下对符合条件的文件大小做汇总统计的简单命令

(1)统计当前目录下的 *txt 文件
du -c -h *txt
   
(2)统计当前目录下的 *txt 文件, 并求出总大小
du  *txt |awk 'BEGIN{count=0;size=0;} \
     {count = count + 1; size = size + $1/1024;} \
     END{print "Total count " count; \
       print "Total size " size/1024 " GB" ; \
       print "Avg size " size / count "MB"}'


(3)统计当前目录下及其子目录中的 +1000000k 文件
find . -size +1000000k -exec ls -l {} \; |awk 'BEGIN{count=0;size=0;} \
     {count = count + 1; size = size + $5/1024/1024;} \
     END{print "Total count " count; \
       print "Total Size " size/1024 " GB" ; \
       print "Avg Size " size / count "MB"; \
       print "—"}'

(4)统计当前目录下及其子目录中的 *.fastq
find . -name '*.fastq' -exec ls -l {} \; |awk 'BEGIN{count=0;size=0;} \
     {count = count + 1; size = size + $5/1024/1024;} \
     END{print "Total count " count; \
       print "Total Size " size/1024 " GB" ; \
       print "Avg Size " size / count "MB"; \
       print "—"}'


(5)统计当前目录下及其子目录中的之前2天的文件
find . -mtime -2 -exec ls -l {} \; |awk 'BEGIN{count=0;size=0;} \
     {count = count + 1; size = size + $5/1024/1024;} \
     END{print "Total count " count; \
       print "Total Size " size/1024 " GB" ; \
       print "Avg Size " size / count "MB"; \
       print "—"}'

posted @ 2014-01-20 17:35  emanlee  阅读(4438)  评论(0编辑  收藏  举报