Arrange file by modified date

Hi,

Am performing a find based on filename and result can contain multiple files being found
Let's say my find command is

find /Archive -f -name 12345.pdf

and result of find command is

/Archive/Folder A/12345.pdf
/Archive/Folder B/12345.pdf

please note white space in folder names

I need to get the file that has most recent modified date

find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | sort -rn | head -n 1

This will prepend a date in epoch seconds to every file name, which sort can order by time.

1 Like

A version using awk:

find /Archive -f -name 12345.pdf -printf "%T@ %p\n" | awk '$1 > P { P=$0 } ; END { $0=P ; $1=""; print substr($0,2) }'
1 Like