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.

Now I see that the epoch %s time isn't needed because this works just as 
well:

MTIME=$(stat -c %y "$FILE")
perl -pi -e 's/FOO/BAR/' "$FILE"
touch -d "$MTIME" "$FILE"

Best of all, touch has a -r option that can be used in this kind of case. 
Consider this example:

perl -pi.bak -e 's/FOO/BAR/' *.txt

for FILE in $(ls -1 *.txt) ; do touch -r "${FILE}.bak" "$FILE" ; done

rm *.txt.bak

Mike


On Mon, 9 Sep 2013, Gavin Purcell wrote:

> This is slightly more concise, but it seems to drop second fractions.
> Something else to consider is the Access time.  Hopefully this is helpful.
>
>
> EPOCH_MTIME=$(stat -c %Y $FILE)
> perl -pi -e 's/FOO/BAR/' "$FILE"
> touch -d @$EPOCH_MTIME $FILE
>
>
> Access: 2013-09-08 23:48:25.155170463 -0500
> Modify: 2013-09-08 23:48:25.155170463 -0500
> Change: 2013-09-08 23:48:25.155170463 -0500
>
> Access: 2013-09-08 23:48:25.000000000 -0500
> Modify: 2013-09-08 23:48:25.000000000 -0500
> Change: 2013-09-09 00:39:02.306271692 -0500
>
>
> -Gavin
>
>
> On Fri, Sep 6, 2013 at 9:59 PM, Mike Miller <mbmiller+l at gmail.com> wrote:
>
>> Changing the system clock is a very bad idea, but I guess you figured that
>> out and sent the message anyway.  This means that you need a beer.
>>
>> I think the method I came up with is OK, but if there were a way to tell
>> perl not to change the timestamp when the -i option is used, that would be
>> better.  I guess this is telling me, but I don't understand it:
>>
>> http://www.velocityreviews.**com/forums/t890336-preserve-**timestamp.html<http://www.velocityreviews.com/forums/t890336-preserve-timestamp.html>
>>
>> which leads me here:
>>
>> http://perldoc.perl.org/**functions/utime.html<http://perldoc.perl.org/functions/utime.html>
>>
>> And I don't knoww what to do with that, so I might just stick to what I
>> did last time.  ;-)
>>
>> Mike
>>
>>
>>
>> On Fri, 6 Sep 2013, Jeremy MountainJohnson wrote:
>>
>>  In Python the os module should have something to modify it (one would
>>> think so since it can read this fs meta). If not, you could write a
>>> script to change the system clock to the original read time stamp of
>>> the file, modify the file, than change the clock back- would do the
>>> job of maintaining the modified attribute. Heh, probably not easier,
>>> but the best my work wired mind could come up with on a Friday :-)
>>> --
>>> Jeremy MountainJohnson
>>> Jeremy.MountainJohnson at gmail.**com <Jeremy.MountainJohnson at gmail.com>
>>>
>>>
>>> On Fri, Sep 6, 2013 at 5:17 PM, Mike Miller <mbmiller+l at gmail.com> wrote:
>>>
>>>> I don't know the best way to do this.  I wanted to change some files but
>>>> I
>>>> wanted to keep the original timestamps.  So I did it this way:
>>>>
>>>> # get the timestamp
>>>> TIME_STRING=$(date -d "$(stat -c %y FILE)" +"%Y%m%d%H%M.%S")
>>>>
>>>> make changes to FILE
>>>>
>>>> # change the timestamp back to what it was before the change
>>>> touch -t $TIME_STRING FILE
>>>>
>>>>
>>>> My use was something like this:
>>>>
>>>> for FILE in $(grep -l FOO) ; do
>>>>    TIME_STRING=$(date -d "$(stat -c %y "$FILE")" +"%Y%m%d%H%M.%S")
>>>>    perl -pi -e 's/FOO/BAR/' "$FILE"
>>>>    touch -t $TIME_STRING "$FILE"
>>>> done
>>>>
>>>>
>>>> So how do you all do this kind of thing?
>>>>
>>>> Mike
>>>> ______________________________**_________________
>>>> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
>>>> tclug-list at mn-linux.org
>>>> http://mailman.mn-linux.org/**mailman/listinfo/tclug-list<http://mailman.mn-linux.org/mailman/listinfo/tclug-list>
>>>>
>>> ______________________________**_________________
>>> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
>>> tclug-list at mn-linux.org
>>> http://mailman.mn-linux.org/**mailman/listinfo/tclug-list<http://mailman.mn-linux.org/mailman/listinfo/tclug-list>
>>>
>>>  ______________________________**_________________
>> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
>> tclug-list at mn-linux.org
>> http://mailman.mn-linux.org/**mailman/listinfo/tclug-list<http://mailman.mn-linux.org/mailman/listinfo/tclug-list>
>>
>