11

Let's clarify this once and for all. I tried to Google this but it seems this information can't be found in one place.

When a file is created or removed, the holding directory mtime changes on Windows and Linux both. ctime also changes on Linux bot not on Windows because there ctime is create time.

If a file is reopened and written to, the holding directory does not change. However, both on Windows and Linux the file mtime changes, and on Linux the ctime changes too, on Windows the ctime is create time.

Is this correct? What caveats are there? Are there exceptions over, say Windows network shares? Or Samba?

Edit: those who have voted to close this as off-topic, please leave a comment on which site do you think this is on topic. There are tons of mtime/ctime questions on Stackoverflow and just because I didn't include PHP snippets that rely on this knowledge it doesn't mean there are none :/

chx
  • 11,270
  • 7
  • 55
  • 129
  • 1
    If i remember correctly, ctime changes only when your editor save function deletes file firsta and then re-creates it. If you simply open file to overwrite, then ctime will not change, only mtime. – Gabor Garami Jul 17 '12 at 16:06
  • Linux has X filesystems and I can imagine those all can do it (slightly or fully) differently. No, even if you do wish, you can not clarify this once and for all. That's not how IT works. – hakre Oct 04 '12 at 17:31
  • That's like saying [`getdents`](http://www.kernel.org/doc/man-pages/online/pages/man2/getdents.2.html) has a slightly different return values on different filesystems. Surely there are semantics and expectations of this one as well. – chx Oct 04 '12 at 23:22

1 Answers1

4

Think of it this way:

A directory is a file that holds pointers (or 'links') to files.

As of that:

  • Changing the content of a file will not affect the directory
    (unless the file is first deleted and then created again with the same name, as mentioned by Gabor Garami above)

  • Adding, Deleting or Renaming files will change the content of the directory-file
    which will cause its ctime/mtime to change as you have described, depending on the OS

Gonen
  • 4,005
  • 1
  • 31
  • 39
  • I know what it is *supposed* to be but that's hardly the question... we are talking of Windows, right? – chx Jul 18 '12 at 14:09
  • Well, in that case we are talking philosophy and not science... I would guess that each Windows version will have its own behavior. Suggest you leave this route and look for a completely different solution. – Gonen Jul 18 '12 at 22:19
  • 1
    What I was after is "Yes, this is the expected behaviour, have anyone seen differently?" and the answer would look like "With Windows ME networking over Netware 286 actually..." – chx Jul 19 '12 at 01:53