Monday, May 5, 2008

File compression and decompressions

I am here to show you examples of how to use tar to zip and unzip two types of files ( tar.bz2, tar.gz)

Remember certain option defined, c for create, z for extract and t for test. v verbose, and f is file. There are 2 common archive people are interested in, bz2 and tar.gz (tgz). bz2 is more compress than tar.gz, but tar.gz is faster for creating and extracting.
To create a bz2 archive, if given list of files, use option j to indicate bz2

tar cjvf filename.tar.bz2 myfile1 myfile2 myfile3

To create a bz2 archive from a folder, if folder must be included in the archive, that means will be extracted with the folder

tar cjvf filename.tar.bz2 foldername/*

To create bz2 archive from a folder but the folder is not included in the tar file.

cd foldername; tar cjvf ../filename.tar.bz2

To test the tar file to see the content of the tar file, use t option.

tar tjvf filename.tar.bz2

To extract the tar file user x option.

tar  xjvf filename.tar.bz2

For tar.gz, use back the same command option but change everything from j to z, let say to create the tar.gz file from folder.

tar czvf filename.tar.gz foldername/*

For more information, check with man

No comments: