gzip(1)
Compress or decompress files using the DEFLATE algorithm.
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
| Flag | What it does |
|---|---|
-d, --decompress | Decompress; same as gunzip |
-c, --stdout | Write output to stdout; leave original files unchanged |
-k, --keep | Keep input files after compression (do not delete) |
-1, --fast | Fastest compression (least compression ratio) |
-9, --best | Slowest compression (highest compression ratio) |
-v, --verbose | Print compression ratio and filenames during processing |
-r, --recursive | Recursively compress files in directories |
-t, --test | Test compressed file integrity without decompressing |
-l, --list | List compression ratio, uncompressed size, and filename for each file |
-q, --quiet | Suppress all warnings and messages |
Examples
Compress file.txt to file.txt.gz, removing the original
gzip file.txtCompress to stdout and redirect to file, keeping the original
gzip -c file.txt > file.txt.gzDecompress file.txt.gz back to file.txt
gzip -d file.txt.gzCompress with maximum compression, keeping the original file
gzip -k -9 large_file.logRecursively compress all files in the /var/log/ directory
gzip -r /var/log/List compression statistics for all .gz files in current directory
gzip -l *.gzCompress stdin from a pipe and write to file.txt.gz
cat file.txt | gzip > file.txt.gzTest the integrity of a compressed file without decompressing it
gzip -t file.txt.gz