#!/usr/bin/perl use strict; die "Usage: $0 [path ...]\n" if ( @ARGV and not -d $ARGV[0] ); push @ARGV, "." if @ARGV == 0; my %hash; $/ = "\0"; open( FIND, "-|", "find", @ARGV, qw/-type d -print0/ ) or die "can't run find @ARGV: !$\n"; while ( ) { chomp; # $hash{$_}{dir} = 0; next unless ( s{/[^/]+$}{} ); $hash{$_}{dir}++; $hash{$_}{sum}++; while ( s{/[^/]+$}{} ) { $hash{$_}{sum}++; } } printf "%6s %8s %s\n", qw/dirs subdirs path/; for ( sort keys %hash ) { printf "%6d %8d %s\n", $hash{$_}{dir}, $hash{$_}{sum}, $_; }