I'm looking for a simple shell script to get the modification date of the
last modified file in a folder's complete hierarchy.
Easy to do with Perl(/Python/Ruby/Tcl), not so much with a shell
script. The find(1) command lets you do pretty powerful queries
against the file system, but "find the newest file" isn't one of them.
(You could do it with a custom shell script passed as an -exec helper
test to find, but that's not very efficient...)
Here's one way to do it with Perl. Standard disclaimer: Perl was
chosen only because my fingers know it best, not because I believe it
is inherently superior to the other options available.
This works OMM:
do shell script "perl -MFile::Find -MFile::stat -le 'my $latest_mtime
= 0; find ( sub { my $mtime = stat($_)->mtime; $latest_mtime = $mtime
if $mtime > $latest_mtime; }, @ARGV); print $latest_mtime;' " &
quoted form of POSIX path of startFolder
It returns the time_t value (seconds since 1970). if you want the
date in a friendlier format, you can as usual use POSIX::strftime to
get it:
do shell script "perl -MFile::Find -MFile::stat -MPOSIX -le 'my
$latest_mtime = 0; find ( sub { my $mtime = stat($_)->mtime;
$latest_mtime = $mtime if $mtime > $latest_mtime; }, @ARGV); print
strftime(\"%F %T\", localtime($latest_mtime));' " & quoted form of
POSIX path of startFolder