Watch all our Tutorials and Training Videos for Free on our Youtube Channel, Get Online Web Tools for Free on swebtools.com

Search Suggest

Archiving files in Linux using tar, gzip and bzip2 tools

linux compress, linux compress, compressing linux, archiving linux, archiving linux tar, linux archiving tools, tar linux, tar xvf, tar cvf, gzip cli



Compress, Archiving and Extract using tar, gzip and bzip2 in Linux


This post will help you to know on archiving files in linux and compressing files in linux using various commands available in linux like compress, gzip, bzip2 and tar.

If you are interested in learning, Request you to go through the below recommended tutorial.

DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
Learn Linux, DevOps and Cloud

Compression is a technique to reduce the size of bunch of files stacked together. Archiving is a method to make single file of multiple files and folders.

It has 2 steps, Archiving & compression:

1. Archiving files in Linux:


This is a process of collecting the files which have to be compressed and make a single file out of them, that is called archiving.

An Archive is made using "tar"(Tape Archive Command).
[root@selva ~]#  tar -cvf example.tar *

Above command makes as an archive "example.tar" & puts all the files in current directory in it.

To list out the archived and compressed content without extracting as below,
[root@selva ~]#  tar -tvf example.tar

2. Compressing files in Linux:


There are various tools to compress the file. They are follows:

Compress & Uncompress Tool:

To compress the file use the following command:
[root@selva ~]# compress example.tar

Above command makes a compressed file  example.tar.Z in the current directory.

To uncompress the file use the following,
[root@selva ~]# uncompress example.tar.Z

Shortcut command to do compressing is,(Archiving + Compression)
[root@selva ~]# tar -Zcvf example.tar.Z

Shortcut Command to do the uncompressing is (Archiving + Uncompressing)
[root@selva ~]# tar -Zxvf example.tar.Z

GZIP & GUNZIP commands in Linux


To compress the file Gzip tool is used..
[root@selva ~]# gzip example.tar

Above Command makes a compressed file example.tar.z in the current directory.

To Uncompress the file Gunzip tool is used..
[root@selva ~]# gunzip example.tar.z

Shortcut command to do the compressing is (Archiving + Compression )
[root@selva ~]# tar -zcvf example.tar.z

Shortcut command to do Uncomressing ( Archiving + Uncompression )
[root@selva ~]# tar -zxvf example.tar.z

BZIP2 & BUNZIP2 commands in Linux


To compress the file using bzip tool,
[root@selva ~]# bzip2 example.tar

Above command makes a compressed file example.tar.bz2 in the current directory.

To Uncompress the file bunzip2 tool is used,
[root@selva ~]# bunzip2 example.tar.bz2

Shortcut command to do the compressing ( Archiving + Compression )
[root@selva ~]# tar -jcvf example.tar.bz2

Shortcut command to do the uncompressing ( Archiving + Uncomression )
[root@selva ~]# tar -jcvf example.tar.bz2

That's it for this post.