zcat Command
Beginner Compression & Archives man(1)View contents of compressed files without decompressing
👁 10 views
📅 Updated: Mar 15, 2026
SYNTAX
zcat [FILE]...
What Does zcat Do?
zcat displays the contents of gzip-compressed files without decompressing them to disk. It is equivalent to gzip -dc (decompress to stdout). zcat is the compressed equivalent of cat.
zcat is essential for viewing, piping, and processing compressed files without creating temporary decompressed copies. It saves disk space and time when working with compressed log files.
zcat works only with gzip (.gz) files. For bzip2 files use bzcat, for xz files use xzcat.
zcat is essential for viewing, piping, and processing compressed files without creating temporary decompressed copies. It saves disk space and time when working with compressed log files.
zcat works only with gzip (.gz) files. For bzip2 files use bzcat, for xz files use xzcat.
Options & Flags
| Option | Description | Example |
|---|---|---|
| file.gz | Display decompressed contents | zcat file.gz |
| multiple | Concatenate multiple compressed files | zcat file1.gz file2.gz |
| with pipe | Pipe to other commands | zcat access.log.gz | grep "ERROR" |
| -f | Force (handle non-gz files too) | zcat -f mixed_files* |
Practical Examples
#1 View compressed file
Displays the contents of a compressed log file.
$ zcat /var/log/syslog.1.gz#2 Search in compressed file
Searches for 404 errors in a compressed log without decompressing.
$ zcat access.log.gz | grep "404"#3 Count lines
Counts lines in a compressed file without decompressing to disk.
$ zcat data.csv.gz | wc -l
Output:
500000
#4 Head of compressed file
Shows just the first 20 lines of a compressed file.
$ zcat large_file.gz | head -20#5 Process compressed CSV
Extracts specific columns from a compressed CSV file.
$ zcat data.csv.gz | awk -F',' '{print $1, $3}'#6 Concatenate compressed files
Processes multiple compressed log files as one stream.
$ zcat access.log.*.gz | sort | uniq -c | sort -rnTips & Best Practices
Use zgrep, zless for common tasks: zgrep searches directly in .gz files. zless pages through them. Both are more convenient than zcat | grep or zcat | less.
zcat vs bzcat vs xzcat: zcat for .gz files, bzcat for .bz2 files, xzcat for .xz files. Each handles its respective compression format.
Large output: zcat outputs the entire decompressed file to stdout. For large files, always pipe to head, less, or grep.
Frequently Asked Questions
How do I view a .gz file without decompressing?
zcat file.gz displays the contents. Use zcat file.gz | less for paging through large files.
How do I search in a compressed file?
zcat file.gz | grep "pattern". Or more directly: zgrep "pattern" file.gz.
What is the difference between zcat and gunzip?
zcat outputs to stdout (file stays compressed). gunzip decompresses to disk (replaces .gz file). zcat is non-destructive.
Related Commands
More Compression & Archives Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →