How to sort all files recursively by modification time in a directory on Linux?

Posted on In QA

How to sort all the files in a directory and subdirectories recursively by modification time on Linux?

You can make use of find (GNU find, or plus stat), sort and sed together to achieve recursively sort files by modification time:

find . -type f -printf '%T@ %pn' 
| sort -k 1 -n 
| sed 's/^[^ ]* //'


find ./ -type f -exec stat --printf="%Y %nn" {} ; 
| sort -k 1 -n 
| sed 's/^[^ ]* //'
Answered by Lucy.

Leave a Reply

Your email address will not be published. Required fields are marked *