13.12. Solutions: List old logfiles

Example 13-6. examples/shell/logfiles_older_than3days.txt

perl -e 'for (<*.log>) {print "$_\n" if -M $_ > 3}'

Example 13-7. examples/shell/list_old_log_files.pl

#!/usr/bin/perl
use strict;
use warnings;

use File::Find 'find';

find({
    wanted   => \&old_files,
    no_chdir => 1,
}, $ARGV[0] || '.');

sub old_files {
    if (substr($_, -4) ne ".log") {
        return;
    }
    if (-M $_ > 3) {
        print "$_\n";
    }
    return;
}

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed