5

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?

3 Answers 3

8

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.

2
  • Good description, should add in symlinks though.
    – Neobyte
    Jun 17, 2009 at 16:33
  • Yes, any name that may be present in a directory counts: files, directories, symlinks, pipes, sockets, device nodes, etc. All these count as entries in the directory table. Also, when you move that directory to another location, it causes a change to the ".." entry, that points to the parent (in fact, this is the only entry in any directory that can have the inode field changed).
    – Juliano
    Jun 17, 2009 at 16:41
3

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.

2
  • 1
    By vi, you actually mean vim. vi on standard Unices (Solaris, AIX, HP-UX) don't create the .filename.swap file.
    – TCampbell
    Jun 17, 2009 at 16:40
  • @TCampbell, yes i do mean vim. Don't know how i typed 'vi' there. I don't do that even on the command line!
    – nik
    Jun 17, 2009 at 17:20
1

You can 'touch' the directory to update the date/time of it as well, without changing contents.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .