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

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

asked Mar 14, 2015 by anonymous

1 Answer

Best answer

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@ %p\n' \
| sort -k 1 -n \
| sed 's/^[^ ]* //'


find ./ -type f -exec stat --printf="%Y %n\n" {} \; \
| sort -k 1 -n \
| sed 's/^[^ ]* //'
answered Mar 14, 2015 by Lucy (990 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost