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: Brian Caldwell <email@hidden>
- Date: Tue, 27 Mar 2007 21:02:44 -0600
On Mar 27, 2007, at 06:54am, applescript-users-
email@hidden wrote:
Date: Mon, 26 Mar 2007 22:27:12 -0400
From: Mark Walsh <email@hidden>
Subject: Shell script help - get date of last modified file in
hierarchy
To: applescript Mailing List <email@hidden>
Message-ID: <C22DF940.75A69%email@hidden>
Content-Type: text/plain; charset="US-ASCII"
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.
I had to think about this one for awhile. It's tempting and easy to
use ls with various options to try to get close to what you want. But
when you said "complete hierarchy", ls can only go so far on it's
own. Here's what I can up with:
find . -type f -print | xargs stat -qf "%m%t%SN" {} | sort -rn | head
-1 | cut -f2-
The breakdown:
(1) do a find descending into file hierarchy starting at current
directory, for regular files, and print their names;
(2) do a stat on filenames piped via stdin using format of
modification time, tab, filename;
(3) sort piped stdin in reverse numerical order; (most recent first)
(4) list first 1 records piped from stdin;
(5) strip off the modification time field added in step (2) on data
piped via stdin;
and print result - the name of the file with the most recent
modification time.
HTH,
Brian Caldwell
_______________________________________________
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