Re: Shell script help - get date of last modified file in hierarchy
Re: Shell script help - get date of last modified file in hierarchy
- Subject: Re: Shell script help - get date of last modified file in hierarchy
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 26 Mar 2007 22:52:37 -0400
On 3/26/07, Mark Walsh <email@hidden> wrote:
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
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden