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,008
  • 19
  • 58
  • 82

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
  • 50,327
  • 19
  • 152
  • 213