SHELL 获取目录下子目录的文件数

#!/bin/sh
find /tmp/homework -maxdepth 1 -type d |
while read dir; 
do 
    count=$(find "$dir" -type f | wc -l)
    echo "$dir:$count"
done

#!/bin/bash
if [ $# -eq 0 ]
then dir=.
elif [ $# -eq 1 ]
then dir=$1
fi
while [ ! -d $dir ]
do
        echo "Input an ordinary directory"
        read dir
done
count=0
for sub_dir in `ls $dir`
do
        array[$count]=$sub_dir
        count=`expr $count + 1`
done
#echo ${array[@]} `ls array[@]|wc`
for((i=0;i<"${#array[*]}";i=i+1))
do
        echo ${array[$i]} `ls $dir${array[$i]}|wc` "|"
done
exit 0

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0