Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gawk -F'/' '{fn[$NF]++ ; c++} END{ln=1; PROCINFO["sorted_in"]="@val_num_desc"; for (i in fn) printf "%2d) %-20s |%4s\n", ln++, i, fn[i] } END{print "\nTotal number of files:", c}' <(find $PWD -type f -printf "%h\n")|column -s $'|' -t
Advertisement
Comments
-
- gawk -F'/' '{fn[$NF]++ ; c++ ; PROCINFO["sorted_in"]="@val_num_desc"; for (i in fn) w=w <=length(i) ? length (i) : w } END{for (i in fn) printf "%2d) %-*s %s\n" , ++ln , w, i, fn[i]; print "--------------------------\nTotal number of files:",c } ' <(find $PWD -type f -printf "%h\n")
-
Comment was deleted
-
Comment was deleted
-
Comment was deleted
-
- #!/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);
Add Comment
Please, Sign In to add comment
Advertisement