use strict; use warnings; sub partition_usage { my $partition = shift; my $line = (`/bin/df -B 1024 $partition`)[-1]; return 1024 * (split(/\s+/, $line))[2]; } # test it: print partition_usage('/home/'), "\n"; #### my @files = glob 'logfile_*.log.gz'; @files = reverse sort { -M $a <=> -M $b } @files. #### my $limit = 10 * 1024**3; # 10 GB for my $filename (@files) { last if partition_usage('/var/log/') < $limit; unlink $filename or warn "Can't delete file '$filename': $!"; }