GNU zip (gzip) is a compression utility that reduces the size of selected files. Files compressed with gzip frequently have the .gz file extension. The gzip command has several options. These command options are described in the following table.
Option | Used To |
---|---|
-d | Reverse file compression (decompression). |
-f | Force compression or decompression of a file even if it has multiple links or if the file exists. |
-n | Omit saving the original file name and timestamp. |
-N | Save the original file name and timestamp. |
-q | Suppress all warnings. |
-r | Enable directory recursion during compression or decompression. |
-v | Display the name and percentage reduction of the compressed or decompressed file. |
-t | Perform an integrity check on the compressed file. |
Syntax
The syntax of the gzip command is:
# gzip [options] [file names]
gzip Command Examples
1. To compress any file:
# gzip file
2. To decompress a file:
# gzip -d file.gz # gzip --decompress file.gz # gzip --uncompress file.gz
3. To see the compressed file content:
# gzip -c file.gz # gzip --stdout file.gz # gzip --to-stdout file.gz
4. To forcefully compress/decompress any file:
# gzip -f file # gzip --force file
# gzip -d -f file.gz # gzip -d --force file.gz
5. To not to save the original file name:
# gzip -n file # gzip --no-name file
6. To save the original file name and time stamp:
# gzip -N file # gzip --no-name file
7. To suppress all warnings:
# gzip -q file # gzip --quiet file
8. To zip the files recursively:
# gzip -r /tmp # gzip --recursive /tmp
9. To specify your own suffix instead of .gz:
# gzip -S .cz file # gzip --suffix .cz file
10. To test the integrity of files:
# gzip -t file.gz # gzip --test file.gz
11. To specify the speed for compression:
# gzip -1 file # gzip --fast file # gzip -9 file # gzip --best file
12. To display the gzip license info:
# gzip -L # gzip --license
13. To get the version info:
# gzip -v # gzip --version
14. To list the help:
# gzip -h # gzip --help