Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 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
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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