Relation between timestamps of files

filestimestamps

If I am correct:

  • atime is the last time the file was read/accessed.

  • mtime is the time when the file content last modified.

  • ctime is the time when the inode of the file, was last changed.

Questions:

  1. If a file's content is stored outside its inode, changing its content will change the mtime to the present, but will that changes its ctime and atime to the present?

  2. If we change a file's attributes stored in its inode, that will change ctime to present, but will that change mtime and atime to present?

  3. Does changing anything related to a file such as its content, attributes, or inode, also change atime?

Best Answer

As @Celada said, this is really easy to test.

One note however: ctime is the last time where inode informations have been changed (the inode number doesn't change).

So:

  1. If a file's content is stored outside its inode, changing its content will change the mtime to the present, but will that changes its ctime and atime to the present?

If you change content, the mtime will change but also the ctime because the timestamps of the file (and maybe its size) are updated and those informations are store in inode.

Plus, say this is a text file and you modify its content using vi, so the atime will also be updated because obviously vi will read the file before displaying it.

Example:

$ touch file1

$ stat file1
    Access: 2015-05-06 19:11:41.887622158 +0200
    Modify: 2015-05-06 19:11:41.887622158 +0200
    Change: 2015-05-06 19:11:41.887622158 +0200

$ echo "hello" >> file1

$ stat file1
    Access: 2015-05-06 19:11:41.887622158 +0200
    Modify: 2015-05-06 19:12:27.816047883 +0200
    Change: 2015-05-06 19:12:27.816047883 +0200
  1. If we change a file's attributes stored in its inode, that will change ctime to present, but will that change mtime and atime to present?

If you change only file's attribute, only the informations stored in inode change, so yes, only ctime will change.

$ stat file2
Access: 2015-05-06 19:28:09.378880724 +0200
Modify: 2015-05-06 19:28:09.378880724 +0200
Change: 2015-05-06 19:28:09.378880724 +0200

$ chmod 700 file2

$ stat file2
Access: 2015-05-06 19:28:09.378880724 +0200
Modify: 2015-05-06 19:28:09.378880724 +0200
Change: 2015-05-06 19:30:24.679022346 +0200
  1. Does changing anything related to a file such as its content, attributes, or inode, also change atime?

As I said for the first question, if you don't need to read the file to change those informations, no, atime won't change.