VIM: Preserve File Date with Touch

I had a single file I needed to modify but didn't want to modify the date of the file.  It was a minor change to the file, so I wanted to maintain the file date for posterity.  In any case, I learned the vim does not provide this functionality, but touch would and quite easily.  With that said, I am familiar with touch and use it quite often, but the following approach proved direct and resolved the problem.

touch -r myfiletoedit timestamp
vim myfiletoedit
touch -r timestamp myfiletoedit

From the man pages:

-r, --reference=FILE
use this file’s times instead of current time

Source

https://unix.stackexchange.com/questions/43119/preserve-modified-time-stamp-after-edit

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *