Here's a simple trick, though perl, not PC:

#!/usr/bin/perl use File::Find; use Getopt::Std; use Cwd; use strict; my $u = "usage: $0 -n count -s skip-pattern dir [dir ...]\n" . " where count is number of newest files to report\n" . " and skip-pattern is a comma separated list of regexes\n" . " to apply upon files found, which will be - skipped\n"; die $u unless @ARGV; my %o; getopt('ns',\%o); my $p; my $s; if($o{s}) { ($p=$o{s}) =~ s/,/\|/g; $s++; } my $n = $o{n} ? $o{n} - 1 : 10; # default 10 files my @d = @ARGV; push @d, getcwd unless @d; my @f; $#f = $n; # preallocate $n elements ! -d $_ and warn "directory $_: $!\n" and undef $_ for @d; @d = grep { defined $_ } @d; @d or die "no searchable directories in argument list\n"; find(\&wanted, @d); print "skip-pattern: ($p)\n" if $o{s}; print join("\n", map { scalar(localtime $_->[0]).' '.$_->[1] } @f ),"\n"; sub wanted { my $file = $File::Find::name; -d && return; $s and $file =~/($p)/ and return; my $time = (stat)[9] or die "can't stat $file: $!\n"; # mtime # if file is newer or as new than the first file... if ($f[0]->[0] < $time) { unshift @f,[$time,$file]; pop @f if $#f > $n; return; } # ...else insert the found file in the list. for( my $i = 0; $i<= $#f; $i++) { if($time >= $f[$i]->[0]) { die unless $time; splice @f,$i,0,[$time, $file]; pop @f if $#f > $n; return; } } }

update: improved code


In reply to Re: How to find the most recent file? by shmem
in thread How to find the most recent file? by zli034

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.