Change of atime, mtime or ctime of a file and of its ancestral dir

timestamps

How does change of atime, mtime or ctime of a file affect

  • the atime, mtime or ctime of its parent directory and
  • the atime, mtime or ctime of its ancestral directories?

Best Answer

You can easily get that information using stat. As for ancestral directories, it is easily checked that if a file changes that this doesn't affect anything "up the hierarchy" by looking at /:

root@pooh:/home/anthon-mint# stat /
  File: ‘/’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 804h/2052d  Inode: 2           Links: 30
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-02-22 09:57:14.028146463 +0100
Modify: 2015-01-01 10:34:05.528461374 +0100
Change: 2015-01-01 10:34:05.528461374 +0100
 Birth: -

as the system is constantly changing files, these values should be close to the current time.

If you create a new directory, and then a file in it, access and modification time of the directory change:

$ mkdir tmp
$ stat tmp
  File: ‘tmp’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 700h/1792d  Inode: 144141      Links: 2
Access: (0775/drwxrwxr-x)  Uid: ( 1001/  anthon)   Gid: (  100/   users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:02.523585508 +0100
Change: 2015-02-27 16:19:02.523585508 +0100
 Birth: -
$ touch tmp/bla
$ stat tmp
  File: ‘tmp’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 700h/1792d  Inode: 144141      Links: 2
Access: (0775/drwxrwxr-x)  Uid: ( 1001/  anthon)   Gid: (  100/   users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:18.639585445 +0100
Change: 2015-02-27 16:19:18.639585445 +0100
 Birth: -

Access time doesn't change, but the creation of the new file changes modification and change time.

Now touch the file again:

$ touch tmp/bla
$ stat tmp
  File: ‘tmp’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 700h/1792d  Inode: 144141      Links: 2
Access: (0775/drwxrwxr-x)  Uid: ( 1001/  anthon)   Gid: (  100/   users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:18.639585445 +0100
Change: 2015-02-27 16:19:18.639585445 +0100
 Birth: -
$ 

And the directory doesn't change, but none of the information for the directory changes, as no new file is created.

Changing the mtime, atime, or ctime of an existing file has no effect on the directory it is in, nor on any of that directory's parents.