I found and tweaked this script to find the most recently modified file in a directory recursively. It only breaks when there is a space in the directory name. Can anyone help me adjust the script so it will read directories with space also?s
for i in *; do
find $i -type f | perl -ne 'chomp(@files = <>); my $p = 9; foreach my $f (sort { (stat($a))[$p] <=> (stat($b))[$p] } @files) { print scalar localtime((stat($f))[$p]), "\t", $f, "\n" }' | tail -1
done
Quoting fixes everything.
Also, you don’t need
tail. Just swap$aand$band exit after you print.And
-l(letter “ell”) appends newlines for you when printing.Edit:
Actually there’s no need for a loop at all: