递归查找目录中文件的数量。递归查找目录中文件的数量
例如,如果目录one
具有目录12 directories
并且这些12 directories
中的每一个都具有另一个13 directories
。 和孙子(13个目录)具有固定数量的文件。 我怎么找到它有多少?
我试图想象下面的方式输出:
a/b/1/ -- 50 files
a/b/2/ -- 10 files
a/c/1/ -- 20 files.
递归查找目录中文件的数量。递归查找目录中文件的数量
例如,如果目录one
具有目录12 directories
并且这些12 directories
中的每一个都具有另一个13 directories
。 和孙子(13个目录)具有固定数量的文件。 我怎么找到它有多少?
我试图想象下面的方式输出:
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"' {} \;
尝试:
find . -type f | wc -l
(它计算的输出的输出线(WC-L)一个命令(find。-type f)在树中输出每个文件的一行)
[编辑]读完评论和更新,我想出了这个衬垫:
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
我是作者。我认为这是一种做法。 – pistal
'_/\ _'放下手!比我的工作好得多! – pistal