Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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 singh 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .