编写一个 Shell 脚本,统计指定目录下每种不同文件类型的个数,并输出结果。

统计指定目录下文件类型个数的 Shell 脚本

#!/bin/bash

# 指定目录路径
dir_path="/path/to/directory"

# 统计文件类型个数
file_type_count=$(find $dir_path -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort | uniq -c)

# 输出结果
echo "$file_type_count"