Friday, February 22, 2013

sort find results by date and time

Have you ever wanted to find all the files below your current directory and sort them by thier last modification time? Try this:
find . -printf "%T+\t%p\n" | sort
Here is the breakdown:

%T is file's last modification time in the format specified by k, which is the same as for %A. By the way, %A could be used to sort by access times instead of modification times.

+ means render the date and time, separated by "+", for example "2013-02-22+08:19:06.3877437110".

\t is a tab character

%p is the file name

All of this information and more might be gleaned by typing "man find" and searching for the section describing "printf" and its options.

Hope that helps.

Please help us learn how to do this on a mac (or windows) on the command line without a 20 minute mac ports install.

1 comment:

David Huttleston Jr said...

Marvelous shell recipe. Cheers, Sir!