Gzip
gzip
is a command-line utility used to compress and decompress files in Unix-like operating systems. It is named after the "GNU zip" project, which aims to provide a free and efficient replacement for the older compress
utility.
Basic Syntax
gzip [options] file
Common Options
-c
: Write output to standard output, allowing redirection.-d
or--decompress
: Decompress the compressed file.-v
or--verbose
: Display more information during compression or decompression.-r
or--recursive
: Recursively compress or decompress directories.-k
or--keep
: Keep the original file after compression.-t
or--test
: Test the integrity of the compressed file.
Examples
Compressing a File:
gzip file.txt
This compresses
file.txt
and creates a compressed file namedfile.txt.gz
.Decompressing a File:
gzip -d file.txt.gz
This decompresses the file
file.txt.gz
and restores the originalfile.txt
.Compressing Multiple Files:
gzip file1.txt file2.txt
This compresses both
file1.txt
andfile2.txt
, creating compressed filesfile1.txt.gz
andfile2.txt.gz
.Recursively Compressing a Directory:
gzip -r directory/
This recursively compresses all files in the
directory
and its subdirectories.Decompressing with Output to Standard Output:
gzip -dc file.txt.gz > output.txt
This decompresses
file.txt.gz
and redirects the decompressed content tooutput.txt
.Testing Compressed Files:
gzip -t file.txt.gz
This tests the integrity of
file.txt.gz
without decompressing it.
Advanced Options
--fast
: Use faster but less effective compression.--best
: Use slower but more effective compression.--rsyncable
: Create a compressible file that can be efficiently synced usingrsync
.
Conclusion
gzip
is commonly used to compress individual files and is often used in combination with other tools and utilities.
It produces files with the .gz
extension, and these compressed files can save disk space and accelerate data transfer when distributing or storing files.
✅ Resources
- 👉 Bash CheatSheet
- 👉 Deploy Projects using your own cloud provider
- 👉 Get Deployment Support from
experts