#!/bin/bash
#file name : 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 statarry["$ftype"]++;
done <<< "`find $path -type f -print`"
echo ======File types and counts======
for ftype in "{!statarray[@]}";
do
echo $type: ${statarray["$ftype"]}
done
本文介绍了一款用于统计指定目录下各种文件类型的Shell脚本。该脚本使用bash语言编写,通过find命令查找所有文件,并利用file命令识别每个文件的类型,最后统计并输出各类文件的数量。
1791

被折叠的 条评论
为什么被折叠?



