Is there any way to get the last modified date of a directory, including sub directories? either via shell script or php?
Thanks!
Is there any way to get the last modified date of a directory, including sub directories? either via shell script or php?
Thanks!
The Unix "stat" command will provide this info, as well as the PHP function by the same name.
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 :
.
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)
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.
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