Home·Terminal commands

zcat

Archives

Usage

zcat <file.gz>

Streams what is inside a .gz to stdout without ever unpacking it to disk, which is how you grep a rotated log in place; `-f` lets plain uncompressed files through in the same pass, and bzip2, xz and zstd have their own bzcat, xzcat and zstdcat.

Common flags

FlagMeaning
<file.gz>Print the contents to stdout, leaving the file compressed.
-fAlso pass through files that are not compressed at all.
zgrep / zlessThe same idea for searching and paging a .gz file.
bzcat / xzcat / zstdcatThe equivalents for bzip2, xz and zstd.

Examples

zcat access.log.gz | grep " 500 "

Search a rotated log without unpacking it.

zcat -f app.log app.log.1.gz | tail -100

Read across compressed and plain logs in one pass.

Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does zcat do?

Streams what is inside a .gz to stdout without ever unpacking it to disk, which is how you grep a rotated log in place; `-f` lets plain uncompressed files through in the same pass, and bzip2, xz and zstd have their own bzcat, xzcat and zstdcat.

Q. How do I type it?

zcat <file.gz> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

4 are listed here; the full set is in man zcat. This command sits under Archives.

Related commands

man page: man zcat