How to Compress And Decompress Files in Linux. Different Ways of Compressing and Combining Multiple Files in Linux.

In this article, I will explain about compression and decompression of files in Linux. Here we will learn all methods of compressing and decompressing of files in Linux. So first of all, you must have a question in your mind that, Why do we need compress or decompress a file or folder?” if you have any idea about then mention it in the comment section and if not then continue reading.

First I will tell you about  What is Compression in Linux?  Guys compress means to reduce the size of the file. For example, if you have a file with huge data size then for you it will be difficult to upload and to share it, anyone. So By the help of some compression tools, we can reduce the size of that file. And we can make that file of a small size. the important thing about the compressed file is this,It covers small size in comparison to the original file. So it is necessary to compress a big data file in small size files.

Now it’s time to know about decompression, decompression is just opposite to compression. Because decompression is the process to convert a compressed file to the original file. For example, if you have a compressed file you want to extract its original file form it then it is said as the decompression of files.

Que. – What is ZIP?

Ans. – ZIP is the archive file format used to reduce the size of the original size. Normally we can say it is a compressor tool to compress big data file in small size. The extension of ZIP archive is .zip. 

Que. – What is GZIP?

Ans. – GZIP is also a file compressor like zipping. But it takes more time than zipping to compress a file. But the important thing is that the compressed file with GZIP covers less space than ZIP. The extension of it is .gz

Que. – What is BGIP2?

Ans. – BZIP2 is also a file compressor like zip. BZIP2 takes more time than ZIP and GZIP to compress the file. So it is high time consumer in compression of the file. The extension of BZIP2 is .bz2

Que. – What is TAR?

Ans. – TAR is the archive command which is used to combine no. of files in the very low time. So normally it is to combine multiple files at the same time. Along with Tar is also used with Compressor tools like gzip, bzip2 etc.

Let’s learn the ways of Compressing and Decompressing a File in Linux.

Suppose you have a file named deepak.txt

Note: – i. Zip is the file compressor.

ii. is the new name given to the compressed file. and

iii. deepak.txt is the original file.

1. Compression and Decompression with ZIP

[root@localhost ~]# zip deepak.txt

[root@localhost ~]#unzip

2. Compression and Decompression with GZIP

[root@localhost ~]# gzip  deepak.txt

[root@localhost ~]# gunzip deepak.gz

( Note : gzip automatically gives name with extension .gz at end name of the file.)

3. Compression and Decompression with BZIP2

[root@localhost ~]# bzip2  deepak.txt

[root@localhost ~]# bunzip2  deepak.bz2

( Note : bzip2 also gives name with extension .bz2 at end name of the file.)

Combining Compressed File with TAR

Let’s Learn Ways of Combining And Compressing Multiple Files with Tar

Suppose you have multiple files named deepak.txt deepak.pdf  deepak.exe

Note: – i. Tar is the file combiner/archive format.

ii. deepak.tar is the new name given to the combined file. and

iii.-cvf is used to combine the multiple files.

iv. -tvf is used to watch the combine archive files.

v.  -xvf is used to uncombine the archive files.

1. Combine Multiple files with TAR

[root@localhost ~]#tar -cvf  deepak.tar  deepak.txt  deepak.pdf  deepak.exe

[root@localhost ~]#tar -tvf  deepak.tar 

[root@localhost ~]#tar -xvf  deepak.tar

2. Combination of TAR with GZIP

Note – Both .tar.gz and .tgz  are extensions for this combination. We have to use only one of these.

[root@localhost ~]#tar -cvzf  deepak.tar.gz/tgz  deepak.txt deepak.pdf  deepak.exe

[root@localhost ~]#tar -tvzf  deepak.tar.gz/tgz 

[root@localhost ~]#tar -xvzf  deepak.tar.gz/tgz 

3. Combination of TAR with BZIP2

Note – Both .tar.bz2 and .tbz2  are extension fir this combination. We have to use only one of these.

[root@localhost ~]#tar -cvjf  deepak.tar.bz2/tbz2  deepak.txt deepak.pdf  deepak.exe

[root@localhost ~]#tar -tvjf  deepak.tar.bz2/tbz2 

[root@localhost ~]#tar -xvjf  deepak.tar.b2/tbz2

In this post, we have learned how to compress, decompress, and combine the files in Linux through different methods. Guys if you have doubt or any query about this post then don’t hesitate to contact me. And if you have any suggestions for me then please write to me the comment box. If you like my posts please share them with your friends.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s