List of Actions That Change a Directories Modification Time

I am looking for a list of actions that can performed that will result in a directories modification time being updated. Off the top of my head:

  • Create a new file in the directory
  • Delete a file in the directory

What am I missing?


In Linux (in most Unices, in fact), directories are like files containing simple tables that look like:

 inode   name
+-----+-----------+
|   3 | bin       |
|  12 | home      |
| 139 | usr       |
| ... | ...       |
+-----+-----------+

So, these "files" (directories) are changed when you make changes to this table. It changes when you add or remove entries from that table (like you noted), but that applies to directories too, not only files. You can't change the inode of an existing entry, but you can change the name that links to that inode (rename a file). So:

  • Create a link to an inode (create a file/directory in that directory, or move a file into that directory)
  • Remove a link to an inode (delete a file/directory from that directory, or move a file from that directory)
  • Change the name of a link (rename a file/directory)

These are the operations that changes the modification time of a directory.


At a macro level, there is one interesting observation.

When you use certain tools that tend to make a temporary file in the local directory (instead of /tmp), and these files are usually hidden (starting with a .), without any apparent change in the directory, you find its modification time changed.

One such case is when you open a file in vi that makes a temporary (.filename.swp) file and then exit the file w/o making any changes. The swap file was created and deleted, modification time of the directory was also changed.

Nothing wrong with this, but helps to know what happened. And, if you are bothered with that, there is a way to stop it too.