55

I used "touch" on a file, updating the file's timestamp but the parent directory's timestamp did not change. However, (as expected) when I created a new file within the parent directory, the directory's timestamp did change.

What criteria do UNIX-like operating systems (specifically AIX) use to determine when to update the timestamp of a directory?

Scrubbie
  • 1,360
  • 1
  • 11
  • 25
  • I found this detailed walkthrough helpful in driving home the numerous things that do not affect a directory timestamp: https://www.baeldung.com/linux/directory-last-modified-time – Ron Burk Sep 01 '23 at 03:30

4 Answers4

40

The timestamp is updated when the data that represents the directory changes. A change in a subdirectory of directory D does not change anything in the representation of D because D only points to the subdirectory, not to what's inside it. On the other hand, creating a file in D changes the block of data on disk that represents D.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
19

A directory's timestamp is changed when the Directory itself is changed. The directory contains, among other things, a list of the inodes of the files in the directory so when you change the content of the directory by adding or removing files then the Directories timestamp will be updated.

Mansoor Siddiqui
  • 20,853
  • 10
  • 48
  • 67
Steve Weet
  • 28,126
  • 11
  • 70
  • 86
  • you mean,if number of blocks associated with one directory changes then it's modifies time will changes right? – Thiyagu ATR Dec 04 '13 at 09:09
  • Not quite. The directory timestamp changes when you add or remove files. This may result in the number of blocks within the directory changing though not necessarily. A block will be capable of storing many inode records so the number of blocks will not change with each new file added. – Steve Weet Dec 04 '13 at 10:37
1

You can use the stat command to find the modified time, creation time etc of a file/directory. Refer to https://linux.die.net/man/2/stat

The article states: st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.

Timmmm
  • 88,195
  • 71
  • 364
  • 509
Kisalay
  • 607
  • 1
  • 6
  • 11
  • 4
    Thank you for replying but this reponse doesn't answer any of the original question. The question was about the criteria used to determine an action (updating the timestamp) not the c-library used to complete the action. – Scrubbie Aug 10 '10 at 18:16
  • 3
    He answered that in the second paragraph...? – Timmmm Feb 08 '19 at 09:55
1

A Directory is considered as changed when there is any Addition or Deletion of File/Directory inside it. If existing Files/Directories are just getting update than Parent Directory timestamp will not change.

LOrD_ARaGOrN
  • 3,884
  • 3
  • 27
  • 49