If you’ve been using Linux, you must have noticed that a lot of compressed files are in the .GZ extension. These files are the equivalent of .zip files on Windows and are compressed using the gzip program.
These files usually contain one or two files compressed for quicker downloads off the internet. They can have anything from source code to pictures to full-blown archives.
In this article, we show how you can create your own .GZ archives or extract existing ones.
Also read: How to convert HEIC files to JPEG and how to open HEIC on Windows?
How to zip .GZ files in Linux?
Creating .GZ archives is a super simple process. Aforementioned, you only need the gzip command to create an archive. The command also offers a bunch of tools for better control over the final result.
Step 1: Open up the terminal (CTRL + ALT + T) and navigate to the directory with the files you want to zip.
Step 2: Type in the gzip command in the following format – gzip [flag] [filename]. For example:
gzip test.txt
There are several flags available for use with the gzip program. Some of the most commonly used ones are:
- -r: Recursively compresses all files in a directory into a single archive.
- -k: By default, gzip changes the file extension to .GZ. If you want to compress the file and keep the original file, use this.
- -[1-9]: Select the compression factor. The higher the number, the lesser the output file size will be
- -v: Shows the output file name and compression percentage
Fun fact: If you compress ten identical files into zip and gz, the zip file would be over ten times larger than the gz file.
Also read: How does import work in Python?
How to unzip a .GZ file in Linux?
Unzipping a file is just as simple as zipping it.
Step 1: Open a terminal and navigate to the directory where the archive is stored.
Step 2: Use the ‘gunzip’ command to extract an archive. E.g.:
gunzip example.gz
And press enter. Your file will be extracted in a separate directory.
Alternatively, most modern Linux distributions have an option to simply right-click on an archive and extract it, much like you can in Windows.
Also read: How to cancel your Audible subscription?