Basic commands,Part I: Compress and decompress files using rar, bzip, tarball(tar) and gunzip

This is a serie of lessons of “Basic Commands “ that focuses on command-line usage, in this serie you will learn the tools and tricks of the command line, which are in many cases faster, more powerfull, and more flexible than GUIprogram.

Today in this part will show you the main commands to compress/decompress files using rar, bzip, tarball(tar) and gunzip.

Tarball (tar):

GNU tar is an archiver that creates and handles file archives in various formats using the ‘tar’ command ,it was originally used as a backup tool to write data to magnetic tape drives .You can use tar to create file archives, to extract files from previously created archives, store additional files, or update or list files which were already stored.

-Create a uncompressed tarball :

tar -cvf archive.tar file1

-Create an archive containing ‘file1’, ‘file2’ and ‘dir1:

tar -cvf archive.tar file1 file2 dir1 

-Show contents of an archive:

tar -tf archive.tar

-Extract a tarball :

tar -xvf archive.tar

-Extract a tarball into / tmp :

tar -xvf archive.tar -C /tmp

-Create a tarball compressed into bzip2

tar -cvfj archive.tar.bz2 dir1

-Decompress a compressed tar archive in bzip2

tar -xvfj archive.tar.bz2

Decompress a compressed tar archive in gzip

tar -cvfz archive.tar.gz dir1

-Decompress a compressed tar archive in gzip

tar -xvfz archive.tar.gz 

Meanning of the c,v,f and z,j options:

-‘c’ option tells tar to create an archive,

-‘v’ displays the files added to the tarball and

-‘f’ specifies the filename. After the filename, all other parameters are the files or directories to add to the archive.

Tarballs are commonly compressed using gzip or bzip2 using the -z or -j command options.

For complete details, see the tar man page

$ man tar

bzip2 :

bzip2 is a freely available, patent free (see below), high-quality data compressor. It typically compresses files to within 10% to 15% of the best available techniques (the PPM family of statistical compressors), whilst being around twice as fast at compression and six times faster at decompression.(Read the documentation of bzip2).

-Compress a file called ‘file1’

bzip2 file1

Compress a file called ‘file1’

bzip2 file1

-Decompress a file called ‘file1.bz2’

bunzip2 file1.bz2 

RAR Archiver :

RAR is a proprietary file format for data compression and archiving, developed by Eugene Roshal.

Under Linux and UNIX, use command called unrar. By default unrar is not being installed on Linux, FreeBSD or UNIX oses. You can install unrar command with the help of apt-get or yum command.See how to install rar on Linux

-Create an archive rar called ‘file1.rar’

rar a file1.rar test_file

Compress ‘file1’, ‘file2’ and ‘dir1’ simultaneously

rar a file1.rar file1 file2 dir1

-Decompress rar archive

rar x file1.rar


unrar x file1.rar

Gzip :

gzip is a software application used for file compression. gzip is short for GNU zip; the program is a free software replacement for the compress program used in early Unix systems, intended for use by the GNU Project.
gzip was created by Jean-Loup Gailly and Mark Adler. Version 0.1 was first publicly released on October 31, 1992. Version 1.0 followed in February 1993.
Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.There is a good article if you want to learn more a bout gzip, see this link.

-Decompress a file called ‘file1.gz’

gunzip file1.gz

-Compress a file called ‘file1’

gzip file1

-Compress with maximum compression

gzip -9 file1

ZIP Archiver:

zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC OS. It is analogous to a combination of the UNIX commands tar and compress.

-Create an archive compressed in zip

zip file1

-Compress in zip several files and directories simultaneously

zip -r file1 file2 dir1

-Decompress a file called file1

unzip file1 

This was all for this part, see you in Part II of Basic commands lessons series.

Links :


{loadposition user9}

Related Articles By Tags :

{loadposition user1}

  • harry

    when i enter this in terminal " tar -cvf archive.tar file1 " the say command not found

  • pico

    do comand tar. if he says command dont found then you have to install the tool first


    When you are in the corner and have no money to go out from that, you would need to receive the business loans. Because it should help you unquestionably. I take college loan every time I need and feel great just because of that.

  • NelsonLula

    I guess that to receive the business loans from creditors you must present a great motivation. But, once I’ve got a short term loan, because I wanted to buy a bike.

  • ValenzuelaCaitlin

    Every one understands that modern life seems to be expensive, nevertheless some people need money for various issues and not every one earns big sums money. Thus to receive quick personal loans or just auto loan will be a right solution.

  • SantanaBettie

    According to my own monitoring, billions of people on our planet get the loan at different banks. Therefore, there is good chances to receive a small business loan in any country.

  • LynneSchneider23

    Specialists argue that credit loans aid a lot of people to live the way they want, just because they can feel free to buy needed things. Furthermore, banks offer short term loan for young and old people.


    This is great that we are able to take the home loans and it opens up completely new opportunities.

  • RodriguezAmanda34

    Cars and houses are not very cheap and not everybody can buy it. But, home loans was invented to help people in such hard situations.

  • WATTS25Gabrielle

    The personal loans are useful for people, which would like to ground their career. As a fact, this is not very hard to receive a commercial loan.

  • TanyaHughes

    Don’t you know that this is the best time to receive the business loans, which will help you.

  • LewisIla19

    The loans suppose to be important for guys, which want to organize their organization. As a fact, that is not hard to receive a college loan.

  • RaeWatkins

    If you want to buy a car, you will have to receive the home loans. Furthermore, my brother usually uses a bank loan, which seems to be the most fast.

  • ColemanJessica19

    I took my first home loans when I was a teenager and it supported me very much. However, I need the secured loan once more time.

  • CHRISTIAN20Manuela

    Set your own life more simple get the loan and all you need.

  • AlyssaRICHARDS35

    People deserve wealthy life time and mortgage loans or just credit loan can make it much better. Just because people’s freedom bases on money state.

  • OSBORNDarla28

    I guess that to receive the personal loans from creditors you ought to have a firm reason. But, once I have received a secured loan, because I wanted to buy a house.

  • Katheryn24Marshall

    I think that to receive the personal loans from creditors you must have a firm motivation. Nevertheless, one time I have received a student loan, because I was willing to buy a bike.

  • AngelBurnett

    Set your own life more simple get the home loans and everything you require.

  • MEYERSLakeisha

    It is perfect that we are able to receive the credit loans moreover, it opens up completely new possibilities.

  • RomanJocelyn18

    Do you recognize that it is correct time to receive the mortgage loans, which would realize your dreams.

  • MULLINSDorothea32

    Don’t have a lot of money to buy a house? You should not worry, because this is achievable to get the credit loans to solve all the problems. So get a credit loan to buy everything you want.

  • KIDDFanny34

    Do you understand that it’s high time to receive the loan, which would make your dreams come true.

  • Russell35Misty

    I guess that to get the business loans from creditors you must have a firm reason. However, one time I’ve received a short term loan, because I was willing to buy a building.


    People in all countries receive the credit loans from different banks, because that’s simple.

  • LelaBridges

    The credit loans suppose to be very useful for people, which are willing to organize their own career. By the way, it is not very hard to receive a college loan.

  • NellieSKINNER24

    If you are willing to buy a car, you would have to receive the business loans. Furthermore, my mother always uses a sba loan, which seems to be the most reliable.

  • vijay

    Thanks for the useful article.untar tar command examples in linux