How to print content of all (compressed, rolled over and current) Apache log files

zgrep

You can use zgrep to search a folder of both compressed and non-compressed logs.

The man page writes about zgrep:

Zgrep invokes grep on compressed or gzipped files. All options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep.

I have tried re-creating your example with a current log, an older log and a compressed log:

saaru >ls -o
total 12
-rw-r--r-- 1 ba 25 Jun 30 23:06 httpd.log
-rw-r--r-- 1 ba 66 Jun 30 23:07 httpd.log-20210530.gz
-rw-r--r-- 1 ba 29 Jun 30 23:07 httpd.log-20210630

The contents of the files are as follows:

saaru >cat httpd.log
This is the current log

saaru >cat httpd.log-20210630
This is the rolled over log

saaru >zcat httpd.log-20210530.gz
This is the compressed log.

With below command you can find the word "compressed" in the logs:

saaru >zgrep "compressed" httpd.log*
httpd.log-20210530.gz:This is the compressed log.

Or find all log lines that do not have that word:

saaru >zgrep -v "compressed" httpd.log*
httpd.log:This is the current log
httpd.log:
httpd.log-20210530.gz:
httpd.log-20210630:This is the rolled over log
httpd.log-20210630:

zcat

If you don't want to search, but simply cat all files you can use zcat with the -f flag:

saaru >zcat -f httpd.log*
This is the current log

This is the compressed log.

This is the rolled over log

Further reading

Here is an article on all the different z* commands.