[英]Recursively find the number of files in a directory
Recursively find the number of files in a directory. 递归查找目录中的文件数。
For example, if directory one
has directory 12 directories
and each of these 12 directories
have another 13 directories
. 例如,如果目录
one
具有目录12 directories
,而这12 directories
每个12 directories
具有13 directories
。 and the grandchild (13 directories) has a fixed number of files. 孙子(13个目录)具有固定数量的文件。 How do I find how many it has?
我如何找到它有多少?
I am trying to visualize the output in the following fashion: 我试图以以下方式可视化输出:
a/b/1/ -- 50 files
a/b/2/ -- 10 files
a/c/1/ -- 20 files.
find . -type d -exec sh -c 'printf "%s " "$0"; find "$0" -maxdepth 1 -type f -printf x | wc -c' {} \;
以及您的特定格式:
find . -type d -exec sh -c 'n=$(find "$0" -maxdepth 1 -type f -printf x | wc -c); printf "%s -- %s files\n" "$0" "$n"' {} \;
Try: 尝试:
find . -type f | wc -l
(it counts the output lines (wc-l) of a the output of a command (find . -type f) that outputs a line per file in the tree) (它计算命令(查找。-type f)的输出的输出行(wc-1),该命令输出树中每个文件的行)
[EDIT] After reading your comment and updates I came up with this one liner: [编辑]在阅读您的评论和更新后,我想到了这只衬垫:
tree -idf --noreport | while read line ; do echo $line ; find $line -maxdepth 1 -type f | wc -l ; done
for a in 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 800000
do
for b in 10 14 18 2 22 26 30 34 38 42 46 6
do
echo $a-$b
find $a/$a-$b/ -type f -print | wc -l
done
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.