Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
Good description, should add in symlinks though. – Neobyte Jun 17 '09 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 '09 at 16:41

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

share|improve this answer

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.

share|improve this answer
By vi, you actually mean vim. vi on standard Unices (Solaris, AIX, HP-UX) don't create the .filename.swap file. – TCampbell Jun 17 '09 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 '09 at 17:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.