disk usage: du in Perl - video
du using Filesys::DiskUsage
examples/du.pl
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use Filesys::DiskUsage qw(du);
- if (not @ARGV) {
- die "Usage: $0 DIRs\n";
- }
- my %sizes = du({'make-hash' => 1}, @ARGV);
- foreach my $entry (sort { $sizes{$a} <=> $sizes{$b} } keys %sizes) {
- print "$entry => $sizes{$entry}\n";
- }
Comments
Very helpful and I love you did a VDO too! Smooth and elegant presentation. I'm an APL-trained programmer always seeking brevity. My lines might be (untested!):
use feature "say"; use Filesys::DiskUsage qw/du/'
die "Usage: $0 DIRs\n" unless @ARGV; my %sizes = du({'make-hash' => 1}, @ARGV); say "$_ : $sizes{$_}" for sort { $sizes{$a} <=> $sizes{$b} } keys %sizes;
As an aside- seems difficult to install Filesys::DiskUsage . CPAN install fails.
Published on 2015-08-15