#!/usr/bin/perl -w $ENV{'PATH'}="/usr/bin"; $threshold=94; open(DIR, "df -k |") || die "Cannot fork df\n"; while () { next unless m|/cache\d|; @arr=split(/\s+|%/); if ( $arr[4] > $threshold ) { push(@dir,$arr[6]); } } close(DIR); foreach $dir ( @dir ) { $n=(0..9, A..F)[rand(16)]; print "$dir is more than ${threshold}% full, erasing files from 0${n}\n"; system "find ${dir}/0${n} -type f | xargs rm"; }