How can I sort the results of find? I want to sort by date created asc?

find /docs -type f | sort

Sorts by filename not date created. Thanks.

link|improve this question

48% accept rate
feedback

1 Answer

up vote 1 down vote accepted

AFAIK, Linux doesn't record the creation time, so the short answer is you cannot.

For the modification time, try this:

$ find /docs -type f -printf '%T@ %p\n' | sort -k1 -n

or:

$ find /docs -type f -print0 | xargs -0 stat -c "%y %n" | sort
link|improve this answer
1  
You beat me too it! Justin, for some discussion on what ctime actually means, look at perlmonks.org/?node_id=741616 – cjc Nov 28 '11 at 10:36
I'm getting: stat: illegal option -- c usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...] – Justin Nov 28 '11 at 11:50
Which distro are you using? – quanta Nov 28 '11 at 14:51
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.