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

I want to use find but sort the results reverse chronologically as with ls -ltr. Is this possible through any combo of flags or pipelines?

Asked By: dan


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+ %pn" | sort

For convenience here is an explanation of the -printf "%T+ %pn" 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.
Answered By: angus

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

ls -laht --full-time */*
Answered By: Ben Usman
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.