Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Last active September 13, 2020 19:58
Show Gist options
  • Select an option

  • Save ggorlen/c0eeb783cd601c1902b2e7831af01d13 to your computer and use it in GitHub Desktop.

Select an option

Save ggorlen/c0eeb783cd601c1902b2e7831af01d13 to your computer and use it in GitHub Desktop.
sort files by size
# list files by size recursively
use strict;
use warnings;
use File::Find;
my @seen;
sub process_file {
push(@seen, [-s $_, $_]) if -f $_;
}
find({wanted => \&process_file, no_chdir => 1}, ".");
@seen = sort {@{$a}[0] <=> @{$b}[0]} @seen;
for my $pair (@seen) {
my $n = sprintf("%.2f", @{$pair}[0] / 1000000);
print ("$n => " . (@{$pair}[1]) . "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment