Sometimes I want to make a minor edit to a text file (e.g., fix a typo), but I want to keep its modification time unchanged. (Motivation: modtime is useful for listing directories in chronological order, for telling when a file's content was last substantively updated, etc. I don't want a trivial edit to obliterate this information.)
This is certainly possible: Unix allows me to manually set the modtime to anything I want (this does set the ctime to the present, which is fine by me). E.g., with touch -t <time>
, or with the utimes(2)
system call. This question is about a simple way to edit a file and then set the modification time to exactly what it was before editing. I am mainly interested in solutions that are editor-agnostic, i.e., if emacs has a save-file-no-update-mtime
command, that's interesting but not what I'm looking for.
touch -r
is clever, but using a temporary file is clunky...) – alexis Apr 23 '16 at 12:14gnu
specific though) – don_crissti Apr 23 '16 at 12:23