如何计算每个目录中的文件数? [英] How to count number of files in each directory?
本文介绍了如何计算每个目录中的文件数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能列出所有的目录由
find ./ -type d
我试图列出每个目录的内容,并通过使用下面的命令
I attempted to list the contents of each directory and count the number of files in each directory by using the following command
find ./ -type d | xargs ls -l | wc -l
但这求和由
find ./ -type d | xargs ls -l
有没有一种方法,我可以指望的文件在每个目录的数量?
Is there a way I can count the number of files in each directory?
推荐答案
假设你已经找到GNU,让它找到的目录,让庆典做休息:
Assuming you have GNU find, let it find the directories and let bash do the rest:
find . -type d -print0 | while read -d '' -r dir; do
files=("$dir"/*)
printf "%5d files in directory %s\n" "${#files[@]}" "$dir"
done
这篇关于如何计算每个目录中的文件数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文