1

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

Thanks!

dcmoody
  • 135
  • 3
  • 1
    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 'SO- stop being evil' 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

5 Answers5

1

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

Geoff Fritz
  • 1,727
  • 9
  • 11
  • 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
1

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 :.

0

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)

Nikolaidis Fotis
  • 2,032
  • 11
  • 13
0

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.

runlevelsix
  • 2,619
  • 22
  • 20
0

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

Nick O'Neil
  • 1,771
  • 11
  • 10