Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 9
    Here's a solution for Mac: find $DIR -type f -exec stat -lt "%Y-%m-%d" {} \+ | cut -d' ' -f6- | sort -n | tail -1
    – user
    Commented Oct 12, 2015 at 20:32
  • 2
    Problem is the cut command truncates paths with spaces instead of -f 2 use -f2- to return fields 2 to the end of the line
    – Kevin
    Commented Jan 11, 2017 at 15:02
  • 4
    As in the suggestion by chaos, if you reverse the sort by using sort -nr, you can use head -n 1 instead of tail -n 1 and improve efficiency slightly. (Although if you're sorting a recursive find, getting the first or last line won't be the slow part.) Commented May 14, 2017 at 11:48
  • 4
    Very useful! I find it more friendly if piped to ls though: find ./ -type f -printf "%T@ %p\n" -ls | sort -n | cut -d' ' -f 2- | tail -n 1 | xargs -r ls -lah
    – Simon
    Commented Jul 27, 2017 at 8:33
  • 3
    @user's Mac version only sorts/displays date, not time. Here's a fixed version: find $DIR -type f -exec stat -lt "%F %T" {} \+ | cut -d' ' -f6- | sort -n | tail -1
    – yoz
    Commented Dec 11, 2019 at 21:21