Sunday, September 29, 2013

Recursively find the latest modified file in a directory

find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "
 
%T@ gives you the modification time like a unix timestamp,
sort -n sorts numerically, 
tail -1 takes the last line (highest timestamp), 
cut -f2 -d" " cuts away the first field (the timestamp) from the output. 

No comments: