Session and utilities
The zcat command
Prints a .gz file to the screen without writing the uncompressed copy to disk.
Most useful options
-fIf the file is not in gzip format, it shows it as it is, like cat-hShows the help and exits-LShows the license and exits-VShows the version and exitsCopy-ready examples
$ printf 'hola\n' > f.txt && gzip -k f.txt && zcat f.txt.gzcreates a compressed file and reads it without decompressing it to disk.Example output
hola
$ zcat registro.log.gz | head -n 20shows the first 20 lines of a compressed log.$ zcat registro.log.gz | grep -i errorsearches the compressed log for lines containing 'error', without decompressing it to disk.$ zcat -f notas.txtif notas.txt is not compressed, zcat -f shows it the same way cat does.$ zcat a.log.gz b.log.gzshows the contents of two compressed files one after the other.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| gzip: f.txt: not in gzip format | The file is not compressed with gzip. It may be plain text or another format, such as bzip2. | If you only want to read it as text, use zcat -f or cat. If it is .bz2, use bzcat. |
| gzip: nope.gz: No such file or directory | The name is misspelled or the file is not in that folder. | List the folder with ls and copy the exact name. |
Typical mistakes
- It does not modify or create files: it only prints the content to standard output.
- A large file is printed in full to the screen. Use | head or | less to read it in parts.
- Without -f, a file that is not in gzip format gives an error instead of being shown.
Differences from similar commands
- gunzip: decompresses and writes the result to disk, dropping the .gz extension. zcat sends it to standard output. The manual says zcat is the same as gunzip -c.
- cat: shows any file as it is. zcat decompresses before showing it, and only with -f does it behave like cat when there is no compressed data.
- bzcat: does the same for .bz2 files made with bzip2. zcat only understands gzip.
FAQ
How is it different from gunzip -c?
In nothing, according to the manual: zcat is gunzip -c. Use it when you only want to read the content.
Can I read a .gz that contains several parts?
Yes. Concatenated compressed members are shown one after the other, because gunzip extracts all members at once.
Why does it say 'not in gzip format'?
The file does not have the gzip header. Check it with file first: it may never have been a .gz even if it has that extension.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course