linux compression & decompression Commands

REF: http://www.cyberciti.biz/howto/question/general/compress-file-unix-linux-cheat-sheet.php


zip to avoid compatibility problems
------------------------------------

zip somename.zip file1 file2 file3

zip -r somename.zip foldername --> zipping entire directory

zip somename.zip * --> Zipping entire directory


unzip -tq pics.zip --> checking zipped file is correctly archived or not.

unzip -l pics.zip --> listing files in a zip file



Then you can extract the original files like this:

unzip squash.zip

unzip as.zip control01.ctl --> extracting only control01.ctl file from as.zip file

unzip as.zip -d /usr/local/extractlocation --> extracting files in another location

-------------------------------------------------------------------------

To use gzip
------------

To compress a file, at a shell prompt, type the following command:

gzip filename.ext


The file will be compressed and saved as filename.ext.gz.
Whenever possible, each file is replaced by one with the extension .gz.

To expand a compressed file, type:

gunzip filename.ext.gz


The filename.ext.gz is deleted and replaced with filename.ext.


-------------------------------------------------------------------------


To use bzip2
-------------

bzip2 filename
bzip2 file1 file2 file3 /usr/work/school

The file will be compressed and saved as filename.bz2.
Whenever possible, each file is replaced by one with the extension .bz2.
To expand the compressed file, type the following command:

bunzip2 filename.bz2


The filename.bz2 is deleted and replaced with filename.


-------------------------------------------------------------------------

To use Tar
-----------


To create a tar file, type
---------------------------
tar -cvf foo.tar /home/mine/work /home/mine/school
tar -cvf foo.tar file1.txt file2.txt file3.txt


To list the contents of a tar file, type:

tar -tvf foo.tar

To extract the contents of a tar file, type:

tar -xvf foo.tar


The tar command does not compress files automatically. You can compress tar files with:

tar -czvf foo.tar


Compressed tar files are conventionally given the extension .tgz and are compressed with gzip.

To expand a compressed tar file type:

tar -xzvf foo.tgz