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/^[^ ]* //'
or
find ./ -type f -exec stat --printf="%Y %nn" {} ;
| sort -k 1 -n
| sed 's/^[^ ]* //'