统计dir_path下所有文件类型的文件数量

时间:2022-09-17 06:28:50
#!/bin/bash
#!文件名为countfile.sh
if [ $# -ne ];
then
echo "Usage is $0 basepath";
exit
fi
path=$ 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
~

使用方法:./countfile.sh dir_path