gzip
The gzip command is used to compress files, replacing the original file with a compressed version ending in .gz. It is one of the most common compression formats in Linux.
Basic Syntax
gzip [OPTION]... [FILE]...
Common Options
| Option | Description |
|---|---|
-d, --decompress | Decompress the file (equivalent to gunzip). |
-k, --keep | Keep (don't delete) input files. |
-r, --recursive | Operate recursively on directories. |
-v, --verbose | Print name and percentage reduction for each file. |
-1 to -9 | Regulate the speed of compression (-1 is fastest, -9 is best compression). |
Real-world Examples
-
Compress a file:
gzip file.txt(This replaces
file.txtwithfile.txt.gz) -
Compress a file and keep the original:
gzip -k file.txt -
Compress with maximum compression ratio:
gzip -9 large_file.bin -
Compress all files in a directory recursively:
gzip -r /path/to/directory