Compression algorithms basically helps us reduce size of files without compromising the quality of data. Certain log files are compressed in GZ file format to save data in Linux. These files are compressed using gzip compression algorithm.
This article mainly covers reading the content of those text files which have been compressed using gzip compression algorithm. Although, we can extract such files easily with gunzip command. And, then use cat command to read the content of the extracted file. But, there are two manual steps involved here – extract and view the files. What if we didn’t have to extract the file by ourselves and just view the file straightaway?
This is made possible through zcat command-line utility, which we cover next.
View content of a GZ log file in Linux
To view GZ log files, we use zcat command-line utility. Use the following syntax –
For instance, if its – apport.log.3.gz then
and, it writes to standard output.
Apart from that, if we want to know the number of lines our log file contains –
zcat apport.log.3.gz | wc -l
If the output doesn’t fit in then, use zless command-line utility.
Thereafter, use Up/Down or Page Up/Page Down keys to navigate through the output.
Lastly, if you are looking for a specific pattern then use zgrep command-line utility. Follow the syntax –
zgrep -i <pattern> <gz-filename>
For instance, if we are looking for a word – bios in the log file – dmesg.2.gz then,
zgrep -i bios dmesg.2.gz
In conclusion, we have covered how to view content of a GZ log file in Linux.