Skip to content


如何使用shell命令统计某个目录下的文件数(目录中有下级目录)

如何使用shell命令统计某个目录下的文件数(目录中有下级目录)?我想要输出的效果如下:
文件数 目录名
17 ./test/dir1
12 ./test/dir2
16 ./test/dir3/dir4/dir5
15 ./test/dir3/dir4/d …

find . -type f | sed ‘s/\(.*\)\/.*/\1\//’|sort | uniq -c


find . -type f | awk ‘BEGIN{FS=OFS=”/”}{$NF=””;a[$0]++}END{for(i in a) print a[i]”\t”i}’

Posted in shell.

Tagged with .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.