Posted By

deepsoul on 11/01/09


recursive perl find newest

Versions (?)

Find newest file and its modification time

 / Published in: Bash

Find the most recently modified file in a directory tree and output its name and modification time. Use index 8 or 10 instead of 9 for access and inode modification time, respectively (see perlfunc manual page - function stat).

This is great for deciding what directories to backup.

  1. find directory -type f | perl -e 'my $l=0; my $n=""; while( <> ) { chomp; my $t= ${[stat($_)]}[9]; $t > $l and ($l= $t, $n= $_); } print "$n\t".localtime($l), "\n";'

Report this snippet  

You need to login to post a comment.