Directory
可以使用樹來列出每個級別的文件數嗎?
我需要查看特定目錄並列出每個級別的文件數。該目錄非常大,大約有 10-15 層深。例如,如果我有以下內容:
D1 | |-- D2A (5 files in this directory) | |-- D3A (6 files in this directory) | |-- D3B (7 Files in this directory) | |-- D2B (1 file in this directory)
然後它應該告訴我級別 3 有 13 個文件,級別 2 有 6 個文件(或 6+13,沒關係)。能
Tree
做到這一點嗎?我嘗試過混合這些選項,但它似乎不起作用。
find . -type d | \ perl -ne 'BEGIN{ sub cnt{ $file=shift; $c="find $file -maxdepth 1 -type f | wc -l";int(`$c`) }} chomp; printf "%s %s\n", $_, cnt($_)' | \ perl -ne '/^(.*) (\d*)$/; $_{scalar(split /\//, $1)}+=$2; END { printf "Depth %d has %d files.\n", @$_ for map { [$_,$_{$_}] } sort keys %_ }'
結果:
Depth 1 has 7 files. Depth 2 has 2353 files. Depth 3 has 2558 files. Depth 4 has 8242 files. Depth 5 has 6452 files. Depth 6 has 674 files. Depth 7 has 1112 files. Depth 8 has 64 files. Depth 9 has 154 files.