You may often need to compress files and folders for various reasons. And “Gzip” compression is a good choice for many scenarios.
Recently, I have faced an issue where I needed to compress a lot of files individually, and manual intervention to compress each file one by one using traditional 7zip became a hassle.
If you are in love with the Windows operating system like I am (I know, I know, sometimes Windows can become quite a pain. Maybe I like the pain and also like to resolve issues all by myself, who knows!), then you may also face issues in batch processing compressing multiple files to the .gzip
format.
There are multiple ways to compress a file into the .gzip
format. The main issue is that most of the ways do not support batch processing the conversion. In this article, I will talk about two of the decent ways you can do this.
Method 1: Using 7zip (No Batch Processing)
7zip is a free software available for Windows, Linux, and ARM64. Installing 7zip in the Windows operating system is very simple and straightforward.
If you simply want to compress any single file to .gzip
format, you need to simply select that file and add it to the 7zip archive. In the GUI, you can select the Archive format as “gzip” and that’s it!
Method 2: Using gzip
from Chocolatey (Batch Processing is the Main Benefit of This)
There are several tools that we can use to compress files and folders on our computers. However, Linux-based operating systems come with a lot of tools and there are a lot of CLI (Command Line Interface) type tools that we can also use to compress multiple files altogether in a batch.
If you use Linux based operating system, then you might have also used GZip. Gzip is a file format and software application that compresses and decompresses files. It also makes files smaller and allows for faster network transfers. However, there are not any official installers of GZip for the Windows operating system.
But, we can install “gzip” directly on Windows and work like we’re in a Linux OS. I prefer to download GZip via Chocolatey, a very good package manager for the Windows operating system.
Chocolatey is a machine-level, command-line package manager and installer for software on Microsoft Windows. It uses the NuGet packaging infrastructure and Windows PowerShell to simplify the process of downloading and installing software.
If you are using Chocolatey for the first time, then you need to install it first. All of the methods are explained in detail on their official website: https://chocolatey.org/install.
Open your Terminal and run the command for installing “gzip”.
choco install gzip
Write “Yes” when it asks for your permission. After a few seconds, you should be ready to use it.
Let’s say I want to batch-compress a lot of files into “.gzip”. I can open my terminal and go to that directory (where my raw files are that I want to compress using gzip) using the cd path/to/where/I/have/the/files
command.
Or, I can simply open my terminal directly using the “Open In Terminal” context menu in that specific directory where I have the files that I want to compress using gzip. Then I can simply use the following command.
gzip * -r
This will iterate through every folder and subfolder in that specific location and compress all of the files to .gzip
recursively (the -r
flag). Keep in mind that it will replace all your files to .gzip
in that directory.
But, if you also want to keep the original files side by side during the batch compression process, you can use the command below.
gzip * -r -k
Here, the -k
flag indicates the --keep
option to keep the original files.
If you want to use all your CPU cores in parallel, then follow the command below.
parallel gzip ::: *
You have to add the necessary suffixes to suit your needs obviously in this process.
That’s it!
Conclusion
I hope you have gained some valuable insights from this article.
If you have enjoyed the procedures step-by-step, then don’t forget to let me know on Twitter/X or LinkedIn. I would appreciate it if you could endorse me for some relevant skillsets of mine on LinkedIn.
You can follow me on GitHub as well if you are interested in open source. Make sure to check my website (https://fahimbinamin.com/) as well.
Thank you so much!
I don’t think Gzip is the best solution for file compression. I prefer to use a different tool that I find more efficient.
I’ve never heard of Gzip before. I’m going to try it out and see if it can help me save some space on my hard drive.
I’m not sure if Gzip is the best option for compressing files. I’ve heard that other tools might be more efficient.
I’m not sure I understand how Gzip works. Could you provide a more detailed explanation?
I’ve used Gzip before, but I didn’t know about all the additional flags. Thanks for the tips!
Great article! I’ve always been iffy about using compression tools, but Gzip seems easy to use. I’ll definitely give it a try.
This article is very clear and easy to follow. Thanks for sharing the knowledge!
Oh wow, a whole article on how to compress files? How groundbreaking.
Who needs a compression tool when you can just send the files as they are? I mean, it’s not like they’re taking up that much space.