views:

30

answers:

3

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?

A: 

ls -1 | xargs cat

Bram Schoenmakers
Date order. You need to add the "-t" option.
JesperE
+1  A: 

Use ls:

ls -1t | xargs cat
JesperE
Sorry, I added a bit to my question, but have worked out the changes I need.My final answer is:`ls -1rt _* | xargs -d'\n' cat`
jezmck
+3  A: 

Quick 'n' dirty:

cat `ls -t _system*.log`

Safer:

ls -1t _system*.log | xargs -d'\n' cat
Anonymouse
just make sure that ls is not aliased to 'ls -F' or similar, in your shell profile. If it does, you may get unwanted *-expansions in your output. To be safe, use /bin/ls -t
J-mster
Or `\ls` if you don't want to specify the location of ls.
JesperE