How to list files recursively and sort them by modification time?

How do I list all files under a directory recursively and sort the output by modification time?

I normally use ls -ltr  but it doesn’t find all files recursively. I am using Linux.

Answer:

The method is use find‘s -printf and sort on a reasonable date format:

find -type f -printf '%T+\t%p\n' | sort -n

Examples if you don’t like the fractional second part (which is often not implemented in the file system anyway):

find -type f -printf '%T+\t%p\n' | sed 's/\.[[:digit:]]\{10\}//' | sort -n
find -type f -printf '%T+\t%p\n' | cut --complement -c 20-30 | sort -n

Posted

in

by

Tags:

Comments

Leave a Reply

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