Files
zcat
Read compressed files without decompressing to disk.
Additional Notes
zcat reads files compressed with gzip (.gz) or compress (.Z) and writes the decompressed content to standard output. It is essentially gzip -dc (decompress to stdout) and does not modify the original compressed files.
It is useful for viewing log files, configuration files, or any text file that has been compressed to save space. Multiple files can be specified, and they are concatenated in sequence, just like cat. The related commands zless, zmore, and zgrep provide paged viewing and searching of compressed files.
Syntax
zcat [options] [file...]
Parameters
file: One or more compressed files (.gzor.Z). If no file is given, reads from standard input.
Common Options
-f,--force: Force decompression even if the file is not recognized as a compressed file.-t,--test: Test the integrity of the compressed file (do not decompress).-l,--list: Show compressed and uncompressed sizes and compression ratio.-v,--verbose: Verbose output.
Examples
zcat file.txt.gz
View the contents of a compressed file.
zcat access.log.gz | grep "404"
Search through a compressed log file without decompressing.
zcat log1.gz log2.gz > combined.log
Combine multiple compressed files into a single uncompressed file.
zcat -l *.gz
List compression details for all gzip files in the directory.
zcat -t file.gz
Test the integrity of a gzip file.
Practical Notes
zcatis equivalent togunzip -corgzip -dc.- On systems where
zcatis not available, usegunzip -corgzip -dcinstead. - For
bzip2compressed files, usebzcat. - For
xzcompressed files, usexzcat. - Many modern tools like
less,grep, andtailhave built-in decompression support via wrappers likezless,zgrep, andztail.