man.lsPlain-English help for Unix commands

gzip Compress and decompress files

Shrinks a single file using the gzip format, which adds a .gz ending. It does not bundle several files together, so use tar first when you need that. gunzip, or gzip -d, undoes the compression.

Synopsis

gzip [OPTION]... [FILE]...
gzip -d [OPTION]... [FILE.gz]...

Common options

Option or formWhat it does
-k, --keepKeep the original file. Without it, gzip deletes the input once it has made the .gz
-d, --decompressDecompress instead of compress. Same as running gunzip
-c, --stdoutWrite the result to standard output and leave the original file untouched
-l, --listShow compressed size, uncompressed size and ratio for .gz files
-t, --testCheck that a .gz file is intact
-v, --verboseShow the name and compression ratio for each file
-1 to -9Compression level. -1 (--fast) is quickest, -9 (--best) is smallest but slowest. The default is 6
-r, --recursiveCompress every file inside folders you name, one by one

Examples

Compress a file and keep the original
gzip -k app.log && ls app.log*
app.log
app.log.gz
Compress to a new file with the original left alone
gzip -c notes.txt > notes.txt.gz && ls notes.txt*
notes.txt
notes.txt.gz
Read a compressed file without unpacking it
gzip -k words.txt && gzip -dc words.txt.gz | sort -u
apple
fig
pear
Check a .gz file is not damaged
gzip -k data.csv && gzip -t data.csv.gz
Compress at maximum level
gzip -9 -k data.csv && ls data.csv*
data.csv
data.csv.gz
Replace a file by its compressed copy, then restore it
gzip app.log && ls app.log* && gzip -d app.log.gz && ls app.log*
app.log.gz
app.log

Notes

See also

Last reviewed 2026-10-07.