how to count dirs with perl one liner

This example will first cd into the directory that you want to start searching from.

It will descend into each sub directory counting the number of entries(files or dirs) and print it out to the command line.

The last step sort the output.

cd /mydir; perl -MFile::Find -e 'find({wanted=>sub {},no_chdir=>1,postprocess=>sub {my $wc = `ls $File::Find::dir | wc -l`;chomp($wc);print "$wc\t$File::Find::dir\n"; }}, ("."));' | sort -n


Popular posts from this blog

Vim vi how to reload a file your editing