Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 718
jezmck Avatar asked Dec 09 '22 16:12

jezmck


2 Answers

Quick 'n' dirty:

cat `ls -t _system*.log`

Safer:

ls -1t _system*.log | xargs -d'\n' cat
like image 75
Anonymoose Avatar answered Dec 12 '22 06:12

Anonymoose


Use ls:

ls -1t | xargs cat
like image 44
JesperE Avatar answered Dec 12 '22 05:12

JesperE