Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I am using sublime, and I've made no changes then the icon in the editor shows the file is unchanged.

However, if I click to save it, it still sets the filesystem mtime time to now.

Should a non-changing save really update the "modified" time?


Simple example:

Create an empty file

$ touch example.file
$ stat -l example.file 
-rw-r--r-- 1 matthew staff 0 Jul  9 14:45:41 2013 example.file

Touching it updates the mtime

$ touch example.file
$ stat -l example.file
-rw-r--r-- 1 matthew staff 0 Jul  9 14:45:57 2013 example.file

Editing it, but making no changes, also updates the mtime

$ vim example.file
# :wq # write and quit, making no changes
$ stat -l example.file
-rw-r--r-- 1 matthew staff 0 Jul  9 14:46:10 2013 example.file
share|improve this question
2  
You told it to save, so why not? –  Kevin Jul 9 '13 at 14:29
    
On the other hand, Emacs keeps state of whether there are any modifications, and discretely notifies you when you try to save when there are no changes. –  tripleee Jul 9 '13 at 14:47
3  
Since you use vim have a look at the :update command. It only writes if changes have been made. –  Marco Jul 9 '13 at 15:05
    
that's good to know @Marco, thanks. –  Matthew Rudy Jul 9 '13 at 22:51
add comment

1 Answer

up vote 2 down vote accepted

Should a non-changing save really update the "modified" time?

Yes, because when an application writes a file out, the operating system writes that data to disk. It may be exactly the same as the data already in the file, but the OS is not going to check or care whether that is true. Of course, text editors hopefully are not so naive as to write an entire file for each save, because I save very frequently and would prefer not to wear a disk pointlessly (maybe file caching and syncing by the OS ameliorates this so the application does not have to worry).

A lot of applications (including vim) will notice if a file they have loaded is changed externally, and notify the user. I would have presumed they do this based on mtime, but a quick check with touch demonstrates that at least in vim's case, it is not that simple (begging the question of how vim knows a change has been made -- perhaps if the mtime has changed a hash of the two versions is compared?). My point with this is that if the application is monitoring a file for external changes, then it should be able to save changes safely without re-writing the entire file (again: hopefully). In that case, you would think saving an unchanged file might mean doing nothing. However, since the user did ask for a save (even though the user knows, or can know, whether it is necessary), then IMO the application should at least touch the file to reflect this. It may be of value, if, eg. you are relying on the timestamp to reflect the last update, even if this update amounts to nothing.

After all, if you don't want the timestamp changed, you don't have to save unchanged documents.

share|improve this answer
    
Thanks. This is what I was looking for. –  Matthew Rudy Jul 9 '13 at 22:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.