The gzip command in Unix and Linux is used for file compression and decompression using the gzip compression algorithm. It is widely used for compressing files to reduce their size for storage, transmission, and backup purposes.
The basic syntax for the gzip command is:
gzip [options] [file(s)]options: Optional command-line options to control the behavior ofgzip.file(s): The name(s) of the file(s) to compress.
To compress a file using gzip:
gzip filename.txtThis command compresses filename.txt and creates a compressed file filename.txt.gz. After compression, the original file filename.txt is typically removed unless the -k option is used to keep it.
To decompress a .gz file using gzip:
gzip -d filename.txt.gzThis command decompresses filename.txt.gz and restores it to filename.txt.
Alternatively, you can use gunzip for decompression, which is equivalent to gzip -d:
gunzip filename.txt.gz-k: Keep the original file after compression or decompression.
-v: Verbose mode, display compression or decompression statistics.
-f: Force compression even if the resulting file is larger than the original.
-1to-9: Specify the compression level (1 for fastest compression, 9 for best compression ratio). The default is-6.
To compress multiple files at once:
gzip file1.txt file2.txtThis command compresses file1.txt and file2.txt, resulting in file1.txt.gz and file2.txt.gz.
To keep the original files after compression:
gzip -k file1.txtThis command compresses file1.txt to file1.txt.gz while keeping the original file1.txt.
The gzip command is a versatile tool for compressing and decompressing files using the gzip compression algorithm in Unix and Linux systems. It offers various options for controlling compression levels, maintaining original files, and providing verbose output. Understanding its usage and options can help you efficiently manage file compression and storage on your system.
gzip [options] files
Compress or decompress files (by default, compresses).
Options:
-f, --force Force compression even if file is already compressed.
-v, --verbose Print verbose information.
-c, --stdout Write output on stdout.
-d, --decompress Decompress.
-h, --help Show this help message.
For more information, see the gzip man page.