gzip
Archives
Usage
gzip [-k] <file>Compresses a single file into .gz and, by default, deletes the original once it succeeds, so keep it with `-k` or by writing to stdout with `-c`; it never bundles several files, which is why tar comes first.
Common flags
| Flag | Meaning |
|---|---|
| -k | Keep the original. Without it, gzip deletes the file it just compressed. |
| -d | Decompress, which is exactly what gunzip does. |
| -c | Write to stdout and leave the input alone. |
| -1 / -9 | Fastest / smallest. The default is -6. |
| -l | Show the compressed and original sizes of a .gz file. |
| -t | Test the integrity without unpacking. |
| -r | Walk a directory and compress each file separately. |
Examples
gzip -9 access.logCreates access.log.gz. The original access.log is gone.
gzip -c report.csv > report.csv.gzCompress while keeping the original.
gzip -l backup.sql.gzHow much it actually saved.
Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does gzip do?
Compresses a single file into .gz and, by default, deletes the original once it succeeds, so keep it with `-k` or by writing to stdout with `-c`; it never bundles several files, which is why tar comes first.
Q. How do I type it?
gzip [-k] <file> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man gzip. This command sits under Archives.
Related commands
man page: man gzip