Re: sed --in-place bug (updates mtime of file even if no changes are made)
John Vanderpool <[email protected]>
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
On 11/11/11 19:35, Eric Blake wrote: > On 11/08/2011 02:32 PM, John Vanderpool wrote: >> --in-place shouldn't update the mtime of the file if the pattern doesn't >> match >> (i.e. no changes were made to file) > Why not? Conceptually, 'sed --in-place' is short-hand for 'sed> temp, > mv temp original', since it is not possible to known a priori whether > the sed script will modify the input when generating the temporary file. > > You're welcome to submit a patch if you think you can fix it, but right > now, I don't think sed should have to recognize whether the output is > identical to the input. If you need mtime unchanged, then use sed to a > temporary file yourself, and compare the two files before deciding > whether to move the temporary file or keep the original. > thanx for your time replying. My C programming is a little rusty (like 20 years!) so don't think I should muck with the code. Possibly a mention in man page would be prudent though? (see bottom) here is how this came to light, a very senior SA had the task of changing a NASA mandated mail list from one name to another and the name was all over the systems so he ran: find / -type f -exec sed --in-place 's/[email protected]/[email protected]/' {} \; and boom, every file on the systems all had the current date - ouch! ---------------------- possible man page change: -i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied) WARNING: input file's mtime is updated regardless of if sed made any changes or not