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: "Mark J. Reed" <email@hidden>
- Date: Wed, 28 Mar 2007 00:11:38 -0400
On 3/27/07, Brian Caldwell <email@hidden> wrote:
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.
Nice. Three minor tweaks:
1. use find -print0 and xargs -0; otherwise it will break for
file/folder names with spaces in them.
2. no {} on the xargs line; that just gets passed literally.
3. the OP wanted the newest modification time, not the associated
filename; that lets you simplify the stat format and take out the cut.
That results in this:
find ${start} -type f -print0 | xargs -0 stat -qf %m | sort -rn | head -1
Another good candidate for the efficiency test - the other solutions
just look for the max value without doing a full sort, and so in
general require fewer comparisons, but as a C program sort is darn
fast...
--
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