1. 程式人生 > >自動統計檔案型別指令碼

自動統計檔案型別指令碼

# !/bin/bash
# 檔名: filestat.sh
   if [ $# -ne 1 ];
   then
     echo "Usage is $0 basepath";
exit fi
   path=$1
   declare -A statarray;
   while read line;
   do
     ftype=`file -b "$line" | cut -d, -f1`
     let statarray["$ftype"]++;
   done < <(find $path -type f -print)
   echo ============ File types and counts =============
   for ftype in "${!statarray[@]}";
   do
     echo $ftype :  ${statarray["$ftype"]}
   done

執行結果:
在這裡插入圖片描述