8

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.

Justin
  • 5,328
  • 19
  • 64
  • 84

1 Answers1

12

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
quanta
  • 51,413
  • 19
  • 159
  • 217