Am wondering when the directory last modified date is changed. I modified a file inside a particular directory (via FTP), but the directory's LMD did not change. How is it suppose to function?
2 Answers
The mtime (modification time) on the directory itself changes when a file or a subdirectory is added, removed or renamed.
Modifying the contents of a file within the directory does not change the directory itself, nor does updating the modified times of a file or a subdirectory. Additionally, adding, removing or renaming files/directories in subdirectories does not propagate up to the directory. If you change the permissions on the directory, the ctime changes but the mtime does not.

- 11,793
- 2
- 35
- 47

- 730,956
- 141
- 904
- 1,278
-
3Is it modified when a subdirectory is modified? – Flimm Sep 30 '13 at 09:42
-
8@Flimm: it depends on the nature of the modification to the sub-directory. If a file is added to or removed from the sub-directory, then no. If the sub-directory is renamed, then yes (because the new name is stored in the directory holding the sub-directory, so what 'really' changes is the entry in the main directory, and nothing changes in the sub-directory). – Jonathan Leffler Sep 30 '13 at 13:02
-
1@JonathanLeffler Is there a way to recursively know that something changed, even if 200 levels deep down? – Llamageddon Oct 28 '14 at 16:10
-
9@Asmageddon: if something is modified several levels deep, there is no way to know that from the modification time of the directory several levels up. Think what that would entail -- ultimately, the root directory would have to be modified any time any file was modified anywhere, making its in-memory inode a hot-spot for every process that ever does anything with any file. – Jonathan Leffler Oct 28 '14 at 16:23
-
1@JonathanLeffler Good point. I'm thinking of sometime writing a file manager, and one thing that I'd like would be to display sizes of directories and everything contained, and so far it doesn't feel like there's much hope for accomplishing that in a simple way. – Llamageddon Oct 28 '14 at 23:15
-
@Llamageddon for that purpose you can write Filesystem FIlter Driver and use to observe all I/O. – weaknespase Oct 22 '16 at 18:59
-
2In Ubuntu, within Nautilus, the LMD of containing directory is updated when a file/subdirectory is added/renamed/removed *AND* when a file inside it is modified. I have Gedit open with a file and I am currently checking the LMD before and after saving the file anew, and when I refresh Nautilus, the LMD is updated for the containing directory. I am puzzled no one seems to have noticed it, or is it just me? – cram2208 Feb 13 '17 at 23:18
-
6@cram2208: Does Gedit create a backup file within the directory, or a lock file, or something like that? What happens if you use `touch somefile` instead of `gedit`? – Jonathan Leffler Feb 13 '17 at 23:23
-
3@JonathanLeffler Good insights I should say, I now understand completely what was going on. It was a backup file in the directory and not the modification of the file in itself. When using touch on the file it actually changed the LMD of the file but not of the directory. Gotta be more careful on those kind of details ... – cram2208 Feb 13 '17 at 23:31
A directory is like a file that contains a list of the filenames in it (indeed, you may have accidentally opened a directory in an editor, where you can see it is a mostly-readable list of its contents) -- so it is modified when a file in that directory is added, removed, or renamed.

- 53,118
- 13
- 86
- 159
-
1
-
1@Flimm It seems to only update the containing directory's mtime otherwise it would bubble up to the root. – Nick Weaver Jul 02 '14 at 11:54
-
1Out of interest, which editors allow you to open a directory directly? Most (even `ed` and `cat`) seem to complain, or offer a list of file to open instead. – naught101 Jun 07 '17 at 01:15
-
-
6@Ether: It doesn't "open a directory" as in actually reading the directory's inode's data (or what ever equivalent on other file systems). It just provides a file browser for that directory. – naught101 Jun 09 '17 at 01:17