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

Is there any way to get the last modified date of a directory, including sub directories? either via shell script or php?


share|improve this question
What exactly are you after: the last time a file was added or removed from the directory tree? Or the last time a file in the directory tree was modified? Try to explain what you want as precisely as you can, give examples if necessary. – Gilles Aug 13 '10 at 19:37
@Gilles: the last time any file in a directory tree has been modified is what I'm after. the single most recently modified date/time from inside the directory tree. – dcmoody Aug 13 '10 at 21:34
up vote 0 down vote accepted

Here's a shell solution that assumes Linux (or more generally GNU find). For simplicity's sake, file names containing newlines are not supported.

find /path/to/directory -type f -printf '%T@:%p\n' |
sort -t : -k 1 -nr |
head -n 1 |
sed -e 's/^[^:]*://'

Quick explanation:
  • List all the regular files in the tree; for each file, print its modification time, a colon and the name.
  • Sort by decreasing leading number.
  • Keep only the first line.
  • Strip the leading number and :.

share|improve this answer

The Unix "stat" command will provide this info, as well as the PHP function by the same name.

share|improve this answer
find -type d | xargs stat --printf='Dir:%n\tModified:%y\n' should do the trick; uses the stat command with a list of DIR's from find. – GruffTech Aug 15 '10 at 16:00

i 'm not sure what you are asking, but have you tried ls -la ?

or even ... find ./ -exec ls -lah {} \; to see the last date of everything.

(It can be deployed in *nix systems)

share|improve this answer
see my comment @Gilles on the original question for more clarification. – dcmoody Aug 13 '10 at 21:35

A shell script sounds like it might complicate this more then having to, however forgive me if I am not fully understanding the question.

tree would be the command I would use for this

syntax tree -dfsD

share|improve this answer

If you are wanting to see a list of all directories/subdirectories (and not any files) in a location sorted by (and showing) their last modified date, you can use the following command:

ls -lRt | grep ^d

Update: You could take it a step further and limit the output to just the last modified date and name of the directory by using

ls -lRt | grep ^d | awk '{print $6" "$7" "$8, $9}'

The only problem with either of these listings is that you don't get a full path for each directory, so it can be difficult to tell what directories are subdirectories.

share|improve this answer

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.