15

Does renaming affect the file modify or access time? Is there a list somewhere of what changes which times?

8

Renaming does update the Change time:

$ mkdir tmp
$ cd tmp

$ echo abc > a
$ stat a
  File: `a'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 26h/38d Inode: 5038682     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000 /  zelda   Gid: ( 1000/   zelda)
Access: 2013-12-12 07:06:58.981107444 +0100
Modify: 2013-12-12 07:06:58.981107444 +0100
Change: 2013-12-12 07:06:58.981107444 +0100
 Birth: -

$ mv a b
$ stat b
  File: `b'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 26h/38d Inode: 5038682     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  zelda)   Gid: ( 1000/   zelda)
Access: 2013-12-12 07:06:58.981107444 +0100
Modify: 2013-12-12 07:06:58.981107444 +0100
Change: 2013-12-12 07:07:14.893238472 +0100
 Birth: -

The Access time is updated when reading the contents of a file. Modify when you actually update the file (opening for modification is not enough to change Modify time).

  • Does copying a file and pasting change its "modify" time on the new file? Does using Ctrl+X and pasting change the "change" time? – user54385 Dec 12 '13 at 6:22
  • 1
    A copy creates a new file with Modify, Access and Change with a new value (all the same). Pasting something in an editor (and then saving) updates all three (Change with a later timestamp than the other two, of course only after you save) – Zelda Dec 12 '13 at 6:26
  • I meant using CTRL+x on the file and CTRL+v somewhere else. – user54385 Dec 12 '13 at 6:30
  • This is using the commandline tools cp and mv, and vi for editing. Other editors, or your desktop might handle the task differently, and have more timestamps updated. – Zelda Dec 12 '13 at 6:30
  • E.g. Nautilus does not update Access and Modify using Ctrl+X then Ctrl+V, only Change is different, like mv – Zelda Dec 12 '13 at 6:32
8

A modification affecting the file's mtime is a change of the file's data: a write of a nonzero amount of bytes, or a truncation that ends up modifying the file. Creating a file sets its mtime to the current date as well. Merely opening a file for writing doesn't affect the mtime, assuming the file isn't created or truncated.

Reading from a file (if a nonzero number of bytes is read) or executing a file sets its atime to the current time. Merely opening a file for reading never affects the atime. On Linux, this is now disabled by default in most circumstances; the atime mount option restores atime updates, while the noatime mount option disables them completely.

Programs can change the mtime and the atime of a file; the basic command to do this is touch. Some file copy programs set the copy to the same mtime as the original, for example cp -p or rsync -t.

A change affecting the file's ctime is a change of the file's metadata: permissions, owner, times, link count, etc. Renaming a file also updates its ctime. Changes of the file data also affect the ctime, but reading from a file doesn't change the ctime even if it changes the atime. It is impossible to change the ctime in any way other than setting it to the current time (even root is constrained, but root can indirectly set the ctime by first changing the system time or by accessing the partition containing the filesystem directly).

Your Answer

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