5

I understand that ctime changes when the file metadata or the file content is changed and mtime on file content modification.

I would like to know the reason for updating ctime when the content of the file is changed, don't we have mtime tracking that already?

On my MAC

usxxkothan3m1:temp kothan3$ touch foo.txt
usxxkothan3m1:temp kothan3$ stat -x foo.txt
  File: "foo.txt"
  Size: 0            FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (276196474/ kothan3)  Gid: (720748206/CORP\Domain Users)
Device: 1,4   Inode: 11745569    Links: 1
Access: Mon Aug 24 11:59:07 2015
Modify: Mon Aug 24 11:59:07 2015
Change: Mon Aug 24 11:59:07 2015
usxxkothan3m1:temp kothan3$ echo "write something here" >> foo.txt
usxxkothan3m1:temp kothan3$ stat -x foo.txt
  File: "foo.txt"
  Size: 21           FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (276196474/ kothan3)  Gid: (720748206/CORP\Domain Users)
Device: 1,4   Inode: 11745569    Links: 1
Access: Mon Aug 24 11:59:24 2015
**Modify: Mon Aug 24 11:59:21 2015**
**Change: Mon Aug 24 11:59:21 2015**
usxxkothan3m1:temp kothan3$ chmod u-w foo.txt
usxxkothan3m1:temp kothan3$ stat -x foo.txt
  File: "foo.txt"
  Size: 21           FileType: Regular File
  Mode: (0444/-r--r--r--)         Uid: (276196474/ kothan3)  Gid: (720748206/CORP\Domain Users)
Device: 1,4   Inode: 11745569    Links: 1
Access: Mon Aug 24 11:59:24 2015
Modify: Mon Aug 24 11:59:21 2015
**Change: Mon Aug 24 11:59:37 2015**
2
  • 3
    Isn't mtime itself metadata? Thus if mtime is modified as result of data being modified, metadata is modified, therefore resulting in setting ctime to the time when that metadata modification (setting of mtime) occurred. At least that would be my interpretation; I have no idea if that is the official one. Commented Aug 24, 2015 at 19:38
  • 3
    @celtschk, with that reasoning, the ctime would also be updated every time the file is read (as atime, also a metadata in the inode, is modified). Commented Aug 24, 2015 at 20:23

1 Answer 1

2

ctime, or status change time, refers to the time when the file metadata has changed. For example, $ ls -ltc under Linux will sort by and show the time of the last modification of file status information.

To get a little deeper, ctime is the inode reported time since data blocks AND/OR the file metadata has changed. Changes in file metadata can refer here to such things as time elapsed since changes were made to the file name, file permissions, file attributes, SELinux contexts, and many other types of filesystem metadata relating to that specific file. Since the ctime field is updated whenever data blocks or metadata change, it is updated whenever mtime is updated. If however the most recent changes to said file only involved metadata alteration, such as file renames, chmod user-invoked permission changes, etc., then only ctime and not mtime would be updated.

A situation in which ctime has changed but mtime has not, would clue you in to the fact that the file metadata has in some way been altered, but the underlying data comprising the file itself has not been altered. Useful for things like automated data backups, computer forensics, etc., I would imagine.

4
  • In your last paragrah, if the design itself is modified to track metadata changes with ctime and content changes with mtime, wouldn't it be much simpler. Commented Aug 24, 2015 at 19:29
  • 1
    You have complete control over mtime, e.g. it can be altered using the $ touch -t <time> <filename> command, but the system stays in control of ctime. So mtime is a little bit like the date you wrote on a letter while ctime is like the postmark on the envelope. Commented Aug 24, 2015 at 19:41
  • It is impossible to change the ctime in any way other than setting it to the current time. Commented Aug 24, 2015 at 19:47
  • If I understood you correctly, your logic is like this: mtime is part of the meta data of the file. So an update to mtime will also cause the update to the ctime. This this correct? Then I will have another question: why updating atime will not update the ctime by using the same logic. Commented Jan 15, 2022 at 7:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.