Saturday, August 3, 2013

Compress and Uncompress Files

1) To compress files:

tar cvf abc.tar a2.tex adir/* # compress files to the file abc.tar
gzip -9 abc.tar /* # create abc.tar.gz file.
tar cvfz abc.tar.gz a2.tex adir/* # directly create abc.tar.gz file
zip a2.tex adir/* # directly create file

Note that -9 means the slowest compression method (best compression). By default, -6 is used. -1 means fastest compression method (less compression). The command zip is compatible with PKUNZIP on pc. Thus, the file can be uncompressed by WinZip.

2) To uncompress files:

tar xvf abc.tar # uncompress abc.tar file
gunzip abc.tar.gz # after uncompress, get abc.tar
tar xvfz abc.tar.gz #unzip and utar *.tar.gz file
unzip #unzip .zip file

To view the content of the compressed file:

tar tvf abc.tar
tar tvfz abc.tar.gz
unzip -l