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: Christopher Nebel <email@hidden>
- Date: Tue, 27 Mar 2007 11:43:32 -0700
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:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden