Gzip Command in Linux
The gzip command in Linux is used to compress files. It helps reduce the file size and saves space. It also makes transferring files faster.
How to Use gzip
To compress a file, use this command:
To compress a file, use this command:
gzip filename
This command replaces the original file with a compressed file. The new file will have a .gz extension.
Example
gzip notes.txt
This will create a file named notes.txt.gz.
This will create a file named notes.txt.gz.
To Decompress a File
To get back the original file, use:
gunzip filename.gz
This will restore the original file and remove the .gz file.
View Contents Without Decompressing
You can view the content of a compressed file using:
zcat filename.gz
Compress Multiple Files
You can compress several files at once:
gzip file1.txt file2.txt file3.txt
This will create file1.txt.gz, file2.txt.gz, and file3.txt.gz.
Useful Options
-k: Keep the original file.
gzip -k file.txt
-d: Same as gunzip, to decompress.
gzip -d file.txt.gz
-r: Compress all files in a directory.
gzip -r myfolder/
Summary
gzip compresses files.
gunzip decompresses .gz files.
Use options to keep files, decompress, or work with folders.
gzip is a simple and fast way to handle file compression in Linux.