Home Linux Linux Basics

Linux Basics

by Editorial Staff

File Compression and Archiving

The compress and archive files is useful a group of files store to in one file system for easy backup. And easy to transfer files to another directory or another computer.

It is uses to less disk space and download faster via the Internet. If disk space is a concern, compress rarely-used files, or place all such files in a single archive file and compress it.

An archive file is not compressed file, but a compressed file can be an archive file.

 A Compressed file:

A compressed file is a collection of files or directories that are stored in one file.  It is compressed large files. Compression is the process of reducing the size depending upon the original file. Red hat Linux provides the bzip2, gzip and zip tools for compression from a shell prompt. Here the zip and unzip tools are well supported to all major and minor operating system. If you transfer files between Linux and other operating system such as MS Windows, use zip tool.

Compressed tools:

if you compressed any file with bzip2 the file extant should be .bz2.

if you compressed any file with gzip the file extant should be .gz.

if you compressed any file with zip the file extant should be .zip.

decompression tools:

bzig2 means bunzip

gzip means gunzip 

zip means unzin

How to compressed file?


[root@localhost redhat]# bzip2 myfile
[root@localhost redhat]#


[root@localhost redhat]# gzip dba
[root@localhost redhat]#


[root@localhost redhat]# zip dba.zip dba
  adding: dba (deflated 48%)
[root@localhost redhat]#

How to decompressed file?


[root@localhost redhat]# bunzip2 myfile.bz2
[root@localhost redhat]#


[root@localhost redhat]# gunzip dba.gz
[root@localhost redhat]#


[root@localhost redhat]# unzip dba.zip
Archive:  dba.zip
replace dba? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: dba
[root@localhost redhat]#

An archive file:

An archive files is a collection of file or directories stored in one file. Archiving is the process of combining multiple files and directories (same or different sizes) into one file.

The most common programs for archiving files and directories are Tar and Zip.

A Tar file is a collection of several files and directories in on file. This is a good way to create backups and archives.


$tar [options] [archive-files] [files or directory to be archived]

There are some Tar options

-c: to create a new archive

-v: verbose information

-f: to create archive filename

-t: to show tar file content

-r: to append files to the end of an archive

-z: to compressed the tar file with gzip

-j: to compressed the tar file with bzip2

-x: to extract file from an archive

–wildcards: to specify patterns in Unix tar command

How to create a tar file?

[root@localhost redhat]# tar -cvf linuxdb.tar kiran mifile music
[root@localhost redhat]#

What contains linuxdb.tar file?

[root@localhost redhat]# tar -tvf linuxdb.tar
-rw-r--r-- root/root         0 2021-08-09 15:10 kiran
-rw-r--r-- root/root      2599 2021-08-10 12:30 mifile
-rw-r--r-- root/root         0 2021-08-09 15:10 music
[root@localhost redhat]#

How to extracts for sources?

[root@localhost redhat]# tar -xvf linuxdb.tar mifile
[root@localhost redhat]#

How to append?

[root@localhost redhat]# tar -rvf linuxdb.tar subhan
[root@localhost redhat]#

How to combined compression files and archive files?

[root@localhost redhat]# tar -czvf linuxdb.tar.gz jay kiran music
[root@localhost redhat]#

You may also like

Leave a Comment

Contact US

Phone Number



2nd floor, # 85, SGR Dental College Rd, Marathahalli, Bengaluru, Karnataka 560037

Email Address


    dbacentre.com is a website that publishes practical and helpful out-of-the-box articles for aspirants like you and me. In addition, we seek to present exceptional, remarkable tutorials and tips that modern cloud professionals will appreciate.


    Subscribe now

    Edtior's Picks

    by mukilan
    by mukilan

    ©2023 Mr DBA CENTRE. All Right Reserved. Designed and Developed by Begintech.in