jezmck jezmck - 5 months ago 9
Linux Question

Linux: cat matching files in date order?

I have a few files in a directory with names similar to


  • _system1.log

  • _system2.log

  • _system3.log

  • other.log



but they are not created in that order.

Is there a simple, non-hardcoded, way to
cat
the files starting with the underscore in date order?

Answer

Quick 'n' dirty:

cat `ls -t _system*.log`

Safer:

ls -1t _system*.log | xargs -d'\n' cat