Archives

Linux gzip command

Compress a file with gzip. By default, the input file is replaced by its compressed form.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

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

Examples

Compress a file while keeping the original.

gzip -k report.log

Decompress a gzip file and keep the compressed original.

gzip -dk report.log.gz

Parameters, options and clauses

Option / clauseDescription
-d, --decompressDecompress files.
-k, --keepKeep the input file instead of removing it.
-c, --stdoutWrite output to standard output and keep input files.
-r, --recursiveProcess files in directories recursively.
-1 to -9Set compression speed/size trade-off; -1 is faster, -9 smaller.
-v, --verboseShow compression ratio and file names.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory