Tarball Compression

Step 1 - Create a tarball

First step is to create a tarball, which is basically a container to put multiple files in.

tar -cvf ourarchive.tar file[1-3].txt -c Indicate that we want to create a new archive.
-v (verbose) Indicate that we require some feedback.
-f Let the tar command accept files ourarchive.tar name of archive or tarball file[1-3].txt specify what will go in our tarball
tar -tf ourarchive.tar -t (test label) Check what is in the tar file.
-f Neccessary in order to pass a file to the tar command.
tar -xvf ourarchive.tar -x Indicate that we want to extract the specified archive.
-v (verbose) Indicate that we require some feedback.
-f Let the tar command accept files
ourarchive.tar name of archive or tarball
Even after extraction the files will remain in the tarball (archive)
Step 2 - Compress (zip) the tarball

Second step is to compress the tarball made in Step 1.
You can use any of the available compression tools.

gzip ourarchive.tar Compress our tarball using gzip
gunzip ourarchive.tar.gz Uncompress our tarball
bzip2 ourarchive.tar Compress our tarball using bzip2
bunzip2 ourarchive.tar.bz2 Uncompress our tarball
Compress (zip) the tarball without creating the tarball first

You can also create a zip using 1 step
For bzip2 you replace the z with a j and the extension .gz with .bz2

tar -cvzf ourarchive.tar.gz file[1-3].txt -c Indicate that we want to create a new archive.
-v (verbose) Indicate that we require some feedback.
-z Indicate to do compression using gzip.
-f Let the tar command accept files
ourarchive.tar.gz name of archive or tarball (note that we add .gz because it is a gzip file)
tar -xvzf ourarchive.tar.gz -x Indicate that we want to extract the specified archive.
-v (verbose) Indicate that we require some feedback.
-z Indicate to do un-compression using gzip.
-f Let the tar command accept files
ourarchive.tar.gz name of archive or tarball
Even after extraction the files will remain in the tarball (archive)

gzip

Description

gzip is faster thatn bzip2, but has less compression power.
File extension will change to .gz

gzip fileToCompress.txt Zip file using gzip algorithm
gunzip fileCompressed.txt.gz Unzip existing zipped file

bzip2

Description

bzip2 can compress files smaller than gzip, but require more compute time.
File extension will change to .bz2

bzip2 fileToCompress.txt Zip file using bzip2 algorithm
bunzip2 fileCompressed.txt Unzip file using bzip2 algorithm

zip

Description

Create a standard zip file that can be used on other operating systems.
Normally gzip and bzip2 files can not be used on other operating systems.

zip ourthing.zip file1.txt file2.txt file3.txt Zip file using bzip2 algorithm
unzip ourthing.zip Unzip file using zip algorithm

7zip

winrar

File Archiving Cheat Sheet