Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctime, mtime, holding directory, windows, linux

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 :/

like image 920
chx Avatar asked Jul 17 '12 08:07

chx


People also ask

What is Mtime and Ctime in Linux?

Modified timestamp (mtime): which is the last time a file's contents were modified. Change timestamp (ctime): which refers to the last time some metadata related to the file was changed.

What does Ctime mean in Linux?

ctime (change time) is the timestamp of a file that indicates the time that it was changed. Now, the modification can be in terms of its content or in terms of its attributes. Whenever anything about a file changes (except its access time), its ctime changes."

Does LS show Mtime or Ctime?

The simplest way to confirm the times associated with a file is to use ls command. This is the default output of ls -l, which shows you the time of the last file modification – mtime.

What is timestamp command in Linux?

Every Linux file has three timestamps: the access timestamp (atime), the modified timestamp (mtime), and the changed timestamp (ctime). The access timestamp is the last time a file was read. This means someone used a program to display the contents of the file or read some values from it.


1 Answers

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

like image 103
Gonen Avatar answered Oct 10 '22 12:10

Gonen