Finding oldest files

There are some 25,000 files in 7,000 directories in my source library and I am trying to find oldest files. I am running this find:

  
 find /usr/mysrc -name "*.[ch]" -type f -mtime +8000 -exec ls -l {} 2>/dev/null
  
 

and playing with the days parameter for mtime, but the output is not sorted and it took me a while to guess the 8000.

I wander if there is an easy way to do that.

It always pays off to be as specific as possible ("how many oldest files do you need?") and to post OS and find versions so you dont't get advice that doesn't work on your system. Try

find /usr/mysrc -printf "%T@ %p\n" | sort | less

if your find provides the printf action.

1 Like

Not quite correct (*), but might work in practice

find /usr/mysrc -name "*.[ch]" -type f -mtime +365 -exec ls -lt {} +

(*) If the argument list (that is collected by the +) becomes too long for the ls, then ls is called another time with the remaining arguments, and the -t sorting becomes wrong.
Therefore the -mtime +365 is an attempt to reduce the argument list.

I liked the idea of using the seconds since epoch. This is old SCO system, its find does not have printf option. Found a gnutools with find that supports printf option and located all the files I wanted to review. Thank you.