2026/04/10(金)便利なコマンド置き場
投稿日:
特定パス配下のサブフォルダのファイル数を計数して、ソートして列挙する
/path/to/hoge
/path/to/fuga
/path/to/piyo
とあるとして
/path/to/hoge 32
/path/to/piyo 22
/path/to/fuga 4
みたいなのが欲しい場合の方法。フォルダはカウントされないので注意。
サブフォルダの中を再帰的に計測する
for d in /path/to/*/; do printf "%s\t%d\n" "$d" "$(find "$d" -type f | wc -l)"; done | sort -t$'\t' -k2 -nr
サブフォルダの直下のみ計測する
for d in /path/to/*/; do printf "%s\t%d\n" "$d" "$(find "$d" -maxdepth 1 -type f | wc -l)"; done | sort -t$'\t' -k2 -nr