3

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?

  • This is very easy to test... – Celada May 6 '15 at 16:35
3

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.

  • thanks. in your second example, why after chmod, the atime and mtime changes to be earlier? – Tim May 6 '15 at 17:51
  • @Tim haha :p I did some awful edit before posting to make the change more obvious, but I forgot to edit the first stat... My (very) bad... sorry, I'll edit the post. – apaul May 6 '15 at 17:55
2

You need two more sentences:

  • atime will change only when you read, open, or touch the file.

  • ctime is also changed when content of file changed.

With these in mind, we can answer your questions easily:

  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?

It will change the ctime, not the atime.

  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?

No, It doesn't change mtime and atime

  1. Does changing anything related to a file such as its content, attributes, or inode, also change atime? No, atime only change when you read, open or touch the file.

Things to remember:

  • atime only change when you read, open, or touch the file.
  • ctime will be updated to the same with mtime if mtime was updated.
  • Changing ctime may or may not change mtime and don't change atime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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