How to display the contents of a gzip/gz file

Unix/Linux Problem: You have a plain text file that has been compressed with the Unix gzip command, and you'd like to display the file contents with the Unix/Linux cat or more commands.

Solution

Instead of using the usual cat or more commands — which you use with plain text files — use their equivalents for working with gz 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.