HOW TO COMPRESS AND DECOMPRESS FILES IN LINUX: gzip and gunzip

By | July 19, 2016

GNU ZIP (“gzip”) is another compressing command tool commonly used in Linux. Just like the bzip2 program it is used to compress files while the “gunzip” is used to decompress files. The file extension of files compressed with gzip end with ‘.gz’. for example;

gzip file_name

For example;

gzip memo.txt

The end product (the compressed file) would become memo.txt.gz

You can compress multiple files with gzip by just separating the different file names of the files to be compressed with a single space;

gzip file1 file2

Both files become file1.gz file2.gz

Decompressing with gunzip is also similar;

gunzip file.gz
gunzip file1.gz file2.gz

Or using the decompress option of the gzip command;

gzip -d file1.gz file2.gz

Gunzip take the list of files on its command line and replace each file whose name ends with .gz, -gz, .z, -z, with an uncompressed file without the original extension.

To get a list of compressed file(s), the –l [list] option is used with the gunzip command like this;

gunzip –l stm.png.gz

The output from the above command would contain the following information;

Compressed: size of the compressed file
Uncompressed: size of the uncompressed file
Ratio: ratio of compression (0.0% if unknown)
Uncompressed_name: the name of the uncompressed file.

You can also use gzip and gunzip like this;

gzip –c originalFile

To produce a newFile.gz file

gunzip –c newFile.gz

You will get oringinalFile, as before. And the ‘–c’ option writes to standard output and keeps the original file unchanged.

Happy Linux’NG!


NEVER MISS AN UPDATE




I agree to have my personal information transfered to MailChimp ( more information )

Join over 10,000 visitors to receive Open Source tips, trick, news, tutorials, programming and more.

We hate spam. Your email address will not be sold or shared with anyone else.

ALEXANDER OMOROKUNWA
MUST READ  Compressing files using graphical tools

One thought on “HOW TO COMPRESS AND DECOMPRESS FILES IN LINUX: gzip and gunzip

  1. Miriam Sinka

    Heya! I am similarly a instructor. Thank you for making such an attractive comment. Being from Baileyton , has granted me with a adequate insight on what is involved to sail to Springville. we will go on to come and visit your blog to better to learn where to go when we drive to capital of Georgia. Make sure you continue posting and give us your suggestions on University of Northwestern–Saint Paul (MN). Would like to see you very soon at the future job fair at Macy’s. Have a good day.

    Reply

Tell us what you think