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 Mar 26, 2007, at 7:27 PM, Mark Walsh 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.


I'm trying to write a script to make sure that when a job is written to our
server, that I can make sure it has the most recent files. I already have
shell scripts that check the count of files in the hierarchy (as well as
logging the filepaths) and I would like to add a warning if it does not find
the same date for the last modified files in each folder.


Any help would be greatly appreciated.

As several people have pointed out, find(1) can't do this, at least not in one command. You can ask for files newer than some other file, but there's no way to express "newest". However, given that, I can suggest an amusingly bad algorithm using only find(1) and a loop. Without bothering to code it up, here's how it works:


1. Pick some file in the hierarchy.
2. Find all files newer than that. (find . -type f -newer $candidate_file)
3. If there are any results, pick one of them and go back to step 2. Otherwise, the candidate file is the newest one.


This isn't truly awful -- it has an upper bound of O(n^2) for the number of files -- but seeing as how even a little thought could give you an O(n) algorithm, it's pretty bad.


--Chris Nebel AppleScript Engineering

P.S.: The canonical truly awful algorithm is bogosort -- see <http:// en.wikipedia.org/wiki/Bogosort>.
_______________________________________________
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.