统计目录下每个文件类型的文件数量

 1 #!/bin/bash
 2 #!文件名为countfile.sh
 3 if [ $# -ne 1 ];
 4 then
 5         echo "Usage is $0 basepath";
 6         exit
 7 fi
 8 path=$1
 9 
10 declare -A statarray;
11 
12 while read line;
13 do
14         ftype=`file -b "$line" | cut -d, -f1`
15         let statarray["$ftype"]++;
16 
17 done< <(find $path -type f -print)
18 
19 echo ============File types and counts ===========
20 for ftype in "${!statarray[@]}";
21 do
22         echo $ftype : ${statarray["$ftype"]}
23 done
24 ~     

使用方式:./countfile.sh dir_path

posted @ 2016-10-27 18:46  普朗克·李  阅读(72)  评论(0编辑  收藏  举报