#!/usr/bin/perl -w # # Usage: oldfiles [#months] # $monthdays = 365 / 12; # Number of days in a month $minage = $monthdays * 6; # Default Minimum Age of a file (6 months +) # # Process months argument, if any # if ($#ARGV >= 0) { $minage = $monthdays * $ARGV[0]; } # # Skate down the ole directory tree # &traverse('.'); sub traverse { local($dir) = shift; local($path); unless (opendir(DIR, $dir)) { warn "Can't open $dir\n"; closedir(DIR); return; } foreach (readdir(DIR)) { next if $_ eq '.' || $_ eq '..'; $path = "$dir/$_"; if ((-d $path) && (! -l $path)) { # non-symlink dir, enter +it &traverse($path); } elsif ((-f _) && (! -l $path)) { # plain file, but not a +symlink $age = -A $path; # get age in days if ($age > $minage) { $size = -s $path; printf "%4d days %9d bytes %s\n",int($age),$size,$path +; } } } closedir(DIR);
In reply to Re: Deleting files
by JSchmitz
in thread Deleting files
by mallen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |