Using the Mac OS X Terminal, how do I write a find
command that orders results by modification date (most recent first)?
There are similar questions already, but they refer to GNU find
and POSIX, but I do not know whether Mac OS X is GNU or POSIX or something else.
Best Answer
OS X is fully POSIX compliant.
Something like that should do:
Some notes:
-t
option inls
will sort bymtime
.xargs
is used to pass the filenames as an argument tols
. Note that you have to use-print0
infind
and-0
inxargs
if you have files with spaces in their names. Also, the maximum amount of arguments is limited by theARG_MAX
variable. To find out how many these are, entergetconf ARG_MAX
.-r
to reverse the sort order (→ oldest files first)find
andls
options are – as usual – outlined in the manuals (man find
orman ls
).