What is the modification date ls reports for directories in Bash shell?

7

1

When I run ls -l in Bash shell, it lists a modification time for both files and directories. As noted in this thread, the modification time for directories does not reflect all of its contents. It also does not seem to be affected by changing the name of the directory. What exactly does the modification time for a directory reflect?

Is it the latest modification time of a file (or directory) in the top level of the directory?

Nagel

Posted 2014-02-04T11:18:22.530

Reputation: 497

Answers

9

Note that, in Unix, a directory does not "contain" the files in it. Rather, it contains links to them. See the link(2) system call for further information.

This means that the "direct" contents of a directory is a list of filenames and corresponding i-numbers. The modification date of the directory, therefore, indicates whenever this list changed. Operations that would cause such changes would include, but not necessarily be limited to, the following:

  • Creating a new file in the directory
  • Removing (or, rather, unlink(2)ing) a file from the directory
  • Renaming a file in the directory
  • Hard-linking a file elsewhere into the directory

Dolda2000

Posted 2014-02-04T11:18:22.530

Reputation: 1 083

3

Think of directory as of simple file containing list of other files. Whenever you change its contents (rename files, add or remove contained files) the modification time of a directory changes.

stant

Posted 2014-02-04T11:18:22.530

Reputation: 31