Archiving files in Linux using tar, gzip and bzip2 tools

Compress, Archiving and Extract using tar, gzip and bzip2 in Linux
archiving files 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).

[[email protected] ~]#  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,

[[email protected] ~]#  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:

[[email protected] ~]# compress example.tar

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

To uncompress the file use the following,

[[email protected] ~]# uncompress example.tar.Z

Shortcut command to do compressing is,(Archiving + Compression)

[[email protected] ~]# tar -Zcvf example.tar.Z

Shortcut Command to do the uncompressing is (Archiving + Uncompressing)

[[email protected] ~]# tar -Zxvf example.tar.Z

GZIP & GUNZIP commands in Linux

To compress the file Gzip tool is used..

[[email protected] ~]# gzip example.tar

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

To Uncompress the file Gunzip tool is used..

[[email protected] ~]# gunzip example.tar.z

Shortcut command to do the compressing is (Archiving + Compression )

[[email protected] ~]# tar -zcvf example.tar.z

Shortcut command to do Uncomressing ( Archiving + Uncompression )

[[email protected] ~]# tar -zxvf example.tar.z

BZIP2 & BUNZIP2 commands in Linux

To compress the file using bzip tool,

[[email protected] ~]# bzip2 example.tar

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

To Uncompress the file bunzip2 tool is used,

[[email protected] ~]# bunzip2 example.tar.bz2

Shortcut command to do the compressing ( Archiving + Compression )

[[email protected] ~]# tar -jcvf example.tar.bz2

Shortcut command to do the uncompressing ( Archiving + Uncomression )

[[email protected] ~]# tar -jcvf example.tar.bz2

That’s it for this post.

Related Content on Linux might be useful to you to improve your Linux Skills.
Keep practicing and have fun. Leave your comments if any.
Support Us: Share with your friends and groups.
Stay connected with us on social networking sites, Thank you.

linux compress, linux compress, compressing linux, archiving linux, archiving linux tar, linux archiving tools, tar linux, tar xvf, tar cvf, gzip linux, gzip command in linux, gzip compression, bzip2 linux, bzip2 command in linux, bzip2 vs gzip