<div dir="ltr"><div><font face="arial, sans-serif">for FILE in *.txt; do touch -r $FILE.bak $FILE; done</font></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 9, 2013 at 11:28 PM, Gavin Purcell <span dir="ltr"><<a href="mailto:mkorangestripe@gmail.com" target="_blank">mkorangestripe@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Mike, that's even better.  Also your for-loop works without the Command Substitution:<div>for FILE in *.txt; do touch -r list $FILE; done<span class="HOEnZb"><font color="#888888"><br>
</font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Gavin</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Sep 9, 2013 at 10:16 PM, Mike Miller <span dir="ltr"><<a href="mailto:mbmiller+l@gmail.com" target="_blank">mbmiller+l@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Yes!!  Thanks.  That is much better.  I was trying to figure out something like that, something simpler, but I didn't spend enough time on the docs for "touch" -- that was the key.  I was looking to much at other things like stat.<br>


<br>
Now I see that the epoch %s time isn't needed because this works just as well:<br>
<br>
MTIME=$(stat -c %y "$FILE")<div><br>
perl -pi -e 's/FOO/BAR/' "$FILE"<br></div>
touch -d "$MTIME" "$FILE"<br>
<br>
Best of all, touch has a -r option that can be used in this kind of case. Consider this example:<br>
<br>
perl -pi.bak -e 's/FOO/BAR/' *.txt<br>
<br>
for FILE in $(ls -1 *.txt) ; do touch -r "${FILE}.bak" "$FILE" ; done<br>
<br>
rm *.txt.bak<br>
<br>
Mike<div><br>
<br>
<br>
On Mon, 9 Sep 2013, Gavin Purcell wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
This is slightly more concise, but it seems to drop second fractions.<br>
Something else to consider is the Access time.  Hopefully this is helpful.<br>
<br>
<br>
EPOCH_MTIME=$(stat -c %Y $FILE)<br>
perl -pi -e 's/FOO/BAR/' "$FILE"<br>
touch -d @$EPOCH_MTIME $FILE<br>
<br>
<br>
Access: 2013-09-08 23:48:25.155170463 -0500<br>
Modify: 2013-09-08 23:48:25.155170463 -0500<br>
Change: 2013-09-08 23:48:25.155170463 -0500<br>
<br>
Access: 2013-09-08 23:48:25.000000000 -0500<br>
Modify: 2013-09-08 23:48:25.000000000 -0500<br>
Change: 2013-09-09 00:39:02.306271692 -0500<br>
<br>
<br>
-Gavin<br>
<br>
<br>
On Fri, Sep 6, 2013 at 9:59 PM, Mike Miller <<a href="mailto:mbmiller%2Bl@gmail.com" target="_blank">mbmiller+l@gmail.com</a>> wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
Changing the system clock is a very bad idea, but I guess you figured that<br>
out and sent the message anyway.  This means that you need a beer.<br>
<br>
I think the method I came up with is OK, but if there were a way to tell<br>
perl not to change the timestamp when the -i option is used, that would be<br>
better.  I guess this is telling me, but I don't understand it:<br>
<br>
</div><a href="http://www.velocityreviews." target="_blank">http://www.velocityreviews.</a>**<u></u>com/forums/t890336-preserve-**<u></u>timestamp.html<<a href="http://www.velocityreviews.com/forums/t890336-preserve-timestamp.html" target="_blank">http://www.<u></u>velocityreviews.com/forums/<u></u>t890336-preserve-timestamp.<u></u>html</a>><br>


<br>
which leads me here:<br>
<br>
<a href="http://perldoc.perl.org/**functions/utime.html" target="_blank">http://perldoc.perl.org/**<u></u>functions/utime.html</a><<a href="http://perldoc.perl.org/functions/utime.html" target="_blank">http://<u></u>perldoc.perl.org/functions/<u></u>utime.html</a>><div>

<br>
<br>
And I don't knoww what to do with that, so I might just stick to what I<br>
did last time.  ;-)<br>
<br>
Mike<br>
<br>
<br>
<br>
On Fri, 6 Sep 2013, Jeremy MountainJohnson wrote:<br>
<br>
 In Python the os module should have something to modify it (one would<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
think so since it can read this fs meta). If not, you could write a<br>
script to change the system clock to the original read time stamp of<br>
the file, modify the file, than change the clock back- would do the<br>
job of maintaining the modified attribute. Heh, probably not easier,<br>
but the best my work wired mind could come up with on a Friday :-)<br>
--<br>
Jeremy MountainJohnson<br></div>
Jeremy.MountainJohnson@gmail.*<u></u>*com <<a href="mailto:Jeremy.MountainJohnson@gmail.com" target="_blank">Jeremy.MountainJohnson@gmail.<u></u>com</a>><div><br>
<br>
<br>
On Fri, Sep 6, 2013 at 5:17 PM, Mike Miller <<a href="mailto:mbmiller%2Bl@gmail.com" target="_blank">mbmiller+l@gmail.com</a>> wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
I don't know the best way to do this.  I wanted to change some files but<br>
I<br>
wanted to keep the original timestamps.  So I did it this way:<br>
<br>
# get the timestamp<br>
TIME_STRING=$(date -d "$(stat -c %y FILE)" +"%Y%m%d%H%M.%S")<br>
<br>
make changes to FILE<br>
<br>
# change the timestamp back to what it was before the change<br>
touch -t $TIME_STRING FILE<br>
<br>
<br>
My use was something like this:<br>
<br>
for FILE in $(grep -l FOO) ; do<br>
   TIME_STRING=$(date -d "$(stat -c %y "$FILE")" +"%Y%m%d%H%M.%S")<br>
   perl -pi -e 's/FOO/BAR/' "$FILE"<br>
   touch -t $TIME_STRING "$FILE"<br>
done<br>
<br>
<br>
So how do you all do this kind of thing?<br>
<br>
Mike<br></div>
______________________________<u></u>**_________________<div><br>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
</div><a href="http://mailman.mn-linux.org/**mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/**<u></u>mailman/listinfo/tclug-list</a><<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">ht<u></u>tp://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a>><br>


<br>
</blockquote>
______________________________<u></u>**_________________<div><br>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
</div><a href="http://mailman.mn-linux.org/**mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/**<u></u>mailman/listinfo/tclug-list</a><<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">ht<u></u>tp://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a>><br>


<br>
 ______________________________<u></u>**_________________<br>
</blockquote><div>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
</div><a href="http://mailman.mn-linux.org/**mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/**<u></u>mailman/listinfo/tclug-list</a><<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">ht<u></u>tp://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a>><br>


<br>
</blockquote>
<br>
</blockquote><div><div>
______________________________<u></u>_________________<br>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>