Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to find files in subdirectories sorted by timestamp (of creation), with most recent first.

I have looked at the man page but it seems to only seems to let you filter by timestamp rather than sort by timestamp.

What options can I pass to find to accomplish this? Alternately, how can I combine it with another tool, like sort to sort by timestamp?

share|improve this question

migrated from stackoverflow.com Jun 18 '13 at 3:46

This question came from our site for professional and enthusiast programmers.

1  
You can't make find do anything in a particular sorted order, beyond choosing between a depth-first search and a breadth-first search. –  Jonathan Leffler Jun 18 '13 at 2:34

2 Answers 2

up vote 2 down vote accepted

You can use xargs to pass the found files to ls and then use the -t option with ls to get reverse chronological order, e.g.:

$ find /path/to/dir -type f -print0 | xargs -0 ls -lt
share|improve this answer
2  
find /path/to/dir -type f -print0 | xargs -0 ls -lrt would be better as it will not break with files with spaces in the name. –  jaypal Jun 18 '13 at 1:36
    
@JS: thanks - answer updated. –  Paul R Jun 18 '13 at 5:19

while Paul's solution is generally OK, it involves more IO than simply:

find bin/ -type f -printf '%Ts\t%p\n' | sort -nr | cut -f2
share|improve this answer

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.