我找到并调整了这个脚本,以递归方式在目录中查找最近修改过的文件。只有当目录名中有空格时,它才会中断。谁可以帮助我调整脚本,使它将读取目录与空间也?
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发布于 2012-05-23 01:41:06
引用可以解决所有问题。
find "$i" -type f而且,你也不需要tail。只需交换$a和$b并在打印后退出。
find $i -type f | perl -lne 'chomp(@files = <>); my $p = 9; foreach my $f (sort { (stat($b))[$p] <=> (stat($a))[$p] } @files) { print scalar localtime((stat($f))[$p]), "\t", $f; exit }'-l (字母"ell")会在打印时为您添加换行符。
编辑:
实际上根本不需要循环:
find -type f | perl -lne 'chomp(@files = <>); my $p = 9; @files = sort { (stat($b))[$p] <=> (stat($a))[$p] } @files; print scalar localtime((stat($files[0]))[$p]), "\t", $files[0]'发布于 2012-09-19 16:53:37
Perl?你没有bash,而且你喜欢写长行代码?;-)
find . -type f -printf '%T+ %p\n' | sort -r | head -n1发布于 2012-05-23 02:18:06
用Perl编写这一切似乎没那么麻烦了。
perl -MFile::Find -e 'find(sub{@f=((stat)[9],$File::Find::name) if -f && $f[0]<(stat)[9]},".");print "@f")'https://stackoverflow.com/questions/10707145
复制相似问题