• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Shell script help - get date of last modified file in hierarchy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Tue, 27 Mar 2007 15:09:47 -0400

Well, this three-liner works without a loop - but since it's running
external commands for every file in the subtree, I'd wager it's even
less efficient :)

   touch -t 197001010000.00 /tmp/timestamp

   find /start/directory -exec test {} -nt /tmp/timestamp \; -exec sh
-c "echo {} >/tmp/timestamp; touch -r {} /tmp/timestamp" \;

   ls -l "$(</tmp/timestamp)"





On 3/27/07, Christopher Nebel <email@hidden> wrote:
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



--
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
References: 
 >Shell script help - get date of last modified file in hierarchy (From: Mark Walsh <email@hidden>)
 >Re: Shell script help - get date of last modified file in hierarchy (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: choose from list bug??
  • Next by Date: Re: Shell script help - get date of last modified file in hierarchy
  • Previous by thread: Re: Shell script help - get date of last modified file in hierarchy
  • Next by thread: Re: Shell script help - get date of last modified file in hierarchy
  • Index(es):
    • Date
    • Thread