GZip Command in Linux: Essential GZip Command Syntax & Examples

What is GZip Command? How it can be used?

GZip Command in Linux


Zip Command: GZip can stands for “GNU Zip“. GZip is a kind of utility mainly used to truncate the files by size. GZip can be used to create a zip files with the extension of “.gz“. GZip comes default in every Linux Distros. This is the best file compressor utilites in the Linux. In this tutorial, We provide the basic GZip Command syntax, GZip options & Gzip Command Examples.

Jump To:

GZip Command Syntax:

The basic syntax of the GZip command is,

gzip [file1] [file2] [file3]

The basic example of the GZip command is,

gzip docx.txt image.png song.mp3

From the above command, The GZip command will compress the files and create the gz zip file individually. The following zip files will create: “docx.gz, image.gz & song.gz“.

GZip Command Options Table:

You can find all the options of GZip command in the Linux Terminal by using the following command,

$gzip --help

The output of the above command is,

[email protected]:~$ gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).

Mandatory arguments to long options are mandatory for short options too.

GZip Command Options Table:

-c, --stdout
write on standard output, keep original files unchanged
-d, --decompress
-f, --force
force overwrite of the output file and compress links
-h, --help
give this help
-k, --keep
keep (don’t delete) input files
-l, --list
list compressed file contents
-L, --license
display software license
-n, --no-name
do not save or restore the original name and timestamp
-N, --name
save or restore the original name and timestamp
-q, --quiet
suppress all warnings
-r, --recursive
operate recursively on directories
make Rsync-friendly archive
-S, --suffix=SUF
use suffix SUF on compressed files
synchronous output (safer if the system crashes, but slower)
-t, --test
test compressed file integrity
-v, --verbose
verbose mode
-V, --version
display version number
-1, --fast
compress faster
-9, --best
compress better
Check this too  20+ CURL Linux Commands 2019 For Ubuntu 18.04 & All Linux Distros
With no FILE, or when FILE is -, read standard input.
Report bugs to <[email protected]>.

Essential GZip Command Examples:

As we said earlier, GZip command is mainly used to compress the files to create the new zip file. Below we added some essential example usage of GZip command:

Compress All Files in the Folder:

With the help of GZip utility, you can compress all the files in the directory. Use the following command:

$gzip -r directory

The GZip command will create the “.gz” file with the directory name.

Decompressed the Compressed file:

You can use the GZip command to decompress the compressed file. Use the following command:

$gzip -d example.txt.gz

The above command will extract the file in the same directory.

Forcefully Compress the file:

You can compress the large file with full force. Use the following command,

$gzip -f example.txt

Compress and Keep the old file:

Usually, GZip command compresses the targetted file and deletes the source file. But you can use the option -k to keep the original file. Use the following command:

$gzip -k example.txt

Details about Compressed files:

With the help of GZip command, you can view the complete information about the compressed file created by GZip. The option -l will output the results such as “compressed, uncompressed, ratio & uncompressed_name

$gzip -l example.txt.gz

The output of the above command is,

 [email protected]:~$ gzip -l example.txt.gz
         compressed        uncompressed  ratio uncompressed_name
                 49                  17 -11.8% example.txt
[email protected]:~$ 

Check the file is valid for compression or not:

With the help of GZip command, you can test the file which can be compressed or not. If the file is valid, you will get no output.

$gzip -l example.txt.gz

Fast Compression & Slow (Best) Compression of Files:

You can set the compression speed with GZip command. The option -9 stands for Best compression & The option -1 stand for Speed compression.

$gzip -1 example.txt

You can set the compression ratio between the numbers 1 to 9.

Check this too  GunZip Command in Linux: Syntax, Commands & Examples!

Combine Two Different Files to form one Zip file:

You can compress two different files to create one Zip compressed file. Use the below command:

$cat docs.txt image.png music.mp3 | gzip > all-compressed-files.gz


That’s it. As we said earlier, This article provides complete information about GZip command in Linux. If you have any queries related to this topic and then feel free to comment us below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Julian

Hello Folks! I'm Julian, Promoted to the Content writer for the category of Commands & Web Apps in Tec Robust. Enjoy my content & Learn more Linux Commands!

Contact me:
tecrobust [@]
Sub: Message to Julian

Grep Command in Linux

Grep Command in Linux: Syntax, Options & Grep Examples Commands!

Gparted Linux

Gparted Ubuntu- Install Gparted on Linux Ubuntu, Fedora, OpenSUSE, Mageia