您的位置:首页 > 其它

遍历目录中所有文件并统计信息

2014-06-27 15:45 357 查看
遍历目录中所有文件,并且统计文件类型。
#!/bin/bash
#filename: filestat.sh
#set -x

if [ $# -ne 1 ];
then
echo $0 basepath;
echo
fi
path=$1

declare -A statarray;

while read line;
do
ftype=`file -b "$line"`
let statarray["$ftype"]++;
done< <( find $path -type f -print )

echo ===============================File types and counts==================================
for ftype in "${!statarray[@]}";
do
echo $ftype : ${statarray["$ftype"]}
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: