gzip¶
Compresses single files quickly and replaces them with a
.gzfile. The most widespread compression on Linux.

Syntax¶
gzip [OPTION]... [FILE]...
Options¶
| Option | Description |
|---|---|
-k |
Keep the original file |
-d, gunzip |
Decompress |
-v |
Show the compression ratio |
-l |
Show compressed and uncompressed size |
-1 … -9 |
Fast or strong, default 6 |
-c |
Write to standard output, keep the file |
Examples¶
Compress a database dump:
gzip -v db.sql
db.sql: 81.4% -- replaced with db.sql.gz
The original db.sql is gone, only db.sql.gz remains.
Show the sizes:
gzip -l db.sql.gz
compressed uncompressed ratio uncompressed_name
80427365 432013312 81.4% db.sql
Decompress again:
gunzip -v db.sql.gz
db.sql.gz: 81.4% -- replaced with db.sql
Compress a dump directly while creating it:
pg_dump shop | gzip > shop.sql.gz
ls -lh shop.sql.gz
-rw-r--r-- 1 nox nox 77M Oct 26 10:42 shop.sql.gz
When do I need it?¶
- For log files, database dumps and other text files that are kept
- When the file has to be opened on any system, also very old ones
- Together with
tarfor.tar.gzarchives
Read without unpacking
zcat and zless show the content of .gz files directly,
without unpacking them first.
The original disappears
Without -k, gzip deletes the original file after compressing. Use -k if you still
need it.