With zsh
:
cd that-dir &&
touch -r *(D.om[1]) .
If you want to consider files in subdirectories as well:
touch -r **/*(D.om[1]) .
And if you want to do it for every non-empty directory, recursively:
for d (**/*(DFod)) touch -r $d/*(D.om[1]) -- $d
Beware that you'll get "no matches found" errors if there are non-empty directories without regular files (if all the files they contain are non-regular such as directories, symlinks, fifos...). To avoid that, you could change it to:
for d (**/*(DFod)) {
newest=($d/*(ND.om[1]))
(( $#newest )) && touch -r $newest -- $d
}
Remove the .
glob qualifier if you don't want to restrict to regular files, or prefix with -
if you also want to consider symlinks to regular files (and the modification time of the file they point to), or replace with ^/
for non-directory files, or ^/,F
for any type of file except empty directories (non-directories or F
ull directories).