reverse cat files order

I need to do log analysis and I am facing problem that cat access.log* display latest log file first.

I tried to sort logs which takes a lot of time because I have logs from couple of years back. And they are already sorted and just displayed in different order than I need it to.

So I need to display files contents in folowing order:

access.log.4
access.log.3
....
access.log

How do I achieve that?

Asked By: insanebits

||

Try this:

ls -rt access.log* | xargs cat 

First list the files from oldest to newest and then cat each one of them.

Answered By: jcbermu
cat $( ls | tac )

or simply

cat $( ls -r )
Answered By: FelixJN

In zsh you can reverse the globbing order:

cat access.log.*(On)
~/test % ls
1  2  3
~/test % cat 1
1
~/test % cat 2
2
~/test % cat 3
3
~/test % cat *
1
2
3
~/test % cat *(On)
3
2
1
Answered By: kos
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.