Unix/Linux FAQ: How can I display the contents of a plain text file that has been compressed with the Unix gzip
command, such as by using the Unix/Linux cat
or more
commands (i.e., you want to “cat a gz file”).
Solution
Instead of using the usual cat
or more
commands — which you use with plain text files — use their equivalents for working with gzip
files:
zcat
zmore
zcat and zmore examples
For instance, if you want to display the contents of an Apache log file (which is a plain text file) that has been compressed with gzip
, use the zcat
command, like this:
zcat access_log.gz
Of course almost any Apache log file will be large, and will scroll off the screen quickly, so you'll probably want to use the gzip
equivalent of the more
command, zmore
, like this:
zmore access_log.gz
Or if you want, you can combine zcat
with the plain more
command in a pipeline to get the same effect, like this:
zcat access_log.gz | more
Summary
In summary, if you want to use Unix/Linux commands like cat
and more
with gzip’d files, I hope these zcat
and zmore
examples are helpful.