Thursday, 28 March 2013

linux - Get the date of the most recent entry (file or directory) within a directory - Stack Overflow

linux - Get the date of the most recent entry (file or directory) within a directory - Stack Overflow

I have a bunch of directories with different revisions of the same c++ project within. I'd like to make things sorted out moving each of these directories to a parent directory named by pattern of YYYY.MM.DD. Where YYYY.MM.DD is the date of the most recent entry (file or directory) in a directory.

How can I recursively find the date of the most recent entry in a particular directory?

Below is one of the ways to do it:

find . -not -type d -printf "%T+ %p\n" | sort -n | tail -1

Or even: find . -not -type d -printf "%TY.%Tm.%Td\n" | sort -n | tail -1

No comments:

Post a Comment