Gzip is a common compression algorithm that allows you to compress a file while keeping the original file format, ownership, and timeline.
When you use the gzip command to compress a file or folder, it would have the same name as before, but with the extension.gz.
Text files, Tar archives, and websites are all compressed with Gzip.
Compress File Using .gz:
Enter the mentioned command to compress a single file with .gz:
A new zip file will be created with .gz extension.
Compress Multiple Files:
You can compress multiple files simultaneously, pass filenames as parameters. Run the below command:
$ gzip file1name file2name file2name
Keep Original File Save:
The original file will be deleted after creating the .gz file. Use –k option to keep the original file:
Alternatively, if you want to preserve the original file, you can use the -c option which allows gzip to write to an output file and pass it to a file.
$ gzip –c filename > filename.gz
Compress Every File in a Folder and its Subfolder:
Use the following command to compress all files in a folder and subfolders.
Decompress File Using .gz:
Use –d option to decompress .gz archive. Follow the below command:
Another way to decompress a .gz file is by using gunzip command:
Decompress Multiple Files:
We can decompress multiple files simultaneously using the command shown below:
$ -d file1name file2name file3name file4name.gz
Test Validity of File:
Use –t option to test the validity of the compressed file.
Change Compression Level:
You may use gzip to define compression levels ranging from 1 to 9. You can select between a smaller compression level that runs faster or a maximum compression level that takes longer to run.
Enter the following command to get a full compression at the lowest latency:
Enter the below-mentioned command to get minimum compression for a faster speed:
List the Content of the Compressed File:
Use –l option to show the statistics of the compressed ad uncompressed file.
Use the –v option with -l to get more detail of the compressed file.
You may use gzip to compress a file and make it smaller. The gzip command can be used to either compress or decompress files. Multiple files can also be compressed or decompressed at the same time. We have used various options of gzip.