How can I use `find` and sort the results by mtime?

Use find's -printf command to output both the time (in a sortable way) and the file, then sort. If you use GNU find,

find . your-options -printf "%T+ %p\n" | sort

For convenience here is an explanation of the -printf "%T+ %p\n" from man find:

  • %Tk File's last modification time in the format specified by k, which is the same as for %A.
    • where k in this case is set to +
    • + Date and time, separated by +, for example `2004-04-28+22:22:05.0'. This is a GNU extension. The time is given in the current timezone (which may be affected by setting the TZ environment variable). The seconds field includes a fractional part.
  • %p File's name.

If that is just a depth-n (assume depth-2) folder hierarchy, I find this one useful:

ls -laht --full-time */*

Tags:

Find

Ls