$linuxjunkies
>

gzip(1)

Compress or decompress files using the DEFLATE algorithm.

UbuntuDebianFedoraArch

Synopsis

gzip [OPTION]... [FILE]...

Description

gzip reduces the size of files using Huffman coding. By default, it compresses each FILE in place, removes the original, and appends a .gz suffix. If no FILE is given, gzip compresses from standard input to standard output.

gzip automatically detects whether to compress or decompress based on file extension and magic number. It preserves original filename and modification time in the compressed file.

Common options

FlagWhat it does
-d, --decompressDecompress; same as gunzip
-c, --stdoutWrite output to stdout; leave original files unchanged
-k, --keepKeep input files after compression (do not delete)
-1, --fastFastest compression (least compression ratio)
-9, --bestSlowest compression (highest compression ratio)
-v, --verbosePrint compression ratio and filenames during processing
-r, --recursiveRecursively compress files in directories
-t, --testTest compressed file integrity without decompressing
-l, --listList compression ratio, uncompressed size, and filename for each file
-q, --quietSuppress all warnings and messages

Examples

Compress file.txt to file.txt.gz, removing the original

gzip file.txt

Compress to stdout and redirect to file, keeping the original

gzip -c file.txt > file.txt.gz

Decompress file.txt.gz back to file.txt

gzip -d file.txt.gz

Compress with maximum compression, keeping the original file

gzip -k -9 large_file.log

Recursively compress all files in the /var/log/ directory

gzip -r /var/log/

List compression statistics for all .gz files in current directory

gzip -l *.gz

Compress stdin from a pipe and write to file.txt.gz

cat file.txt | gzip > file.txt.gz

Test the integrity of a compressed file without decompressing it

gzip -t file.txt.gz

Related commands