Advertisement
This is comment for paste
BASH GAWK File Count with Columns
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Perl version (no external tools needed). I did not make one liner for clarity.
- use warnings;
- use strict;
- use File::Find;
- use File::Spec;
- my (%data, %data2, $total, $idx, $dl); my $max = 0;
- sub findfiles() {
- return if (! -f);
- my($vol,$dir,$file) = File::Spec->splitpath($File::Find::name);
- $data{$dir} = exists $data{$dir} ? $data{$dir}+1 : 1;
- $total++;
- }
- finddepth( { wanted => \&findfiles }, Cwd::getcwd);
- foreach my $key (keys %data) {
- my $dir = $key;
- $dir =~ s#.*/(.+)/$#$1#;
- $dl = length($dir);
- $max = $dl > $max ? $dl : $max;
- }
- foreach my $i (sort { $data{$a} <=> $data{$b} } keys %data) {
- my $cnt = $data{$i};
- $i =~ s#.*/(.+)/$#$1#;
- printf("%*d) %-*s %d\n", length(keys %data), ++$idx, $max, $i , $cnt);
- }
- printf("%s\nTotal number of files: %d\n", "-" x 30, $total);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement