System Management

A rotated log, /var/log/app.log.3.gz, has been compressed by logrotate. An administrator needs the number of lines containing the word timeout in it, without first decompressing the file to disk. Which command does this?

Show the answer

Correct answerC. zgrep -c "timeout" /var/log/app.log.3.gz

zgrep decompresses the data on the fly and applies grep, so -c returns the count of matching lines. Piping zcat into wc -l counts every line in the file rather than only matches; plain grep would search the compressed bytes, and gzip -l only reports compression statistics.