Find newest file and its modification time


/ Published in: Bash
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.