Fri 27 May 2005 07:48:56 PM UTC, original submission:
Actually Release 4.1.7, debian woody. Debian is always so up-to-date.
-newer only examines the target once
Consider the case where I'm trying to write a script that sets some "target" file to the latest time of a large number of other files that I'm using find to traverse.
I write
find $START -f -newer $TARGET -exec touch -r "{}" $TARGET ";"
but this only gets the time set to the last file that find examines that was -newer than the $TARGET's mod time before the command began to execute.
My work-around for the line above is to execute until it produces no output, but that's unpleasant, especially if the structure traversed by find is large.
while true
do
findout=`find $START -f -newer $TARGET \
-exec touch -r "{}" $TARGET ";" -print | tail -1`
if [ -z $findout ] ; then break ; fi
done
After some reflection, I believe that the general case of this sort of problem occur when I'm using -exec.
So, I can understand a line of argument that goes that mine is an exceptional case, and the current behavior of -newer works well for everyone else in the world. Indeed, in the general case where the action of the -exec command does not modify one of the predicates, only taking the time once is a reasonable and much-to-be-desired optimization.
Anywho, please consider changing the behavior of -newer such that it performs the current behavior (check the time once) if and only if there are no -exec arguments elsewhere in the predicate, and check the time every time if there are -exec arguments elsewhere.
Or, (ugh!) add either another time test predicate that checks every time (for use with find | xargs constructions).
|