Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell script help - get date of last modified file in hierarchy



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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Shell script help - get date of last modified file in hierarchy (From: Mark Walsh <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.