On linux distributions we commonly see files named tar, tgz, tar.gz and tar.bz2. This note tries to explain common operations on such files.

tar
tar is used to create a Tape ARchive. ( tar is from the old unix era) The resulting file is known as a tarball. A tar ball concatenates files to a a sin get the files out of a tarball, you can extract a tarball using

tar -xvf something.tar

To create a tar archive , the following command can be used.

tar -c /home/mydir > mydir.tar

tgz and tar.gz

If the tarball has also been gzipped (compressed), the file will be named tar.gz or tgz .You can use the following command to extract it.

tar -xvfz something.tar.gz

If you want to create a tgz as below.

tar czvf myfolder.tar.gz myfolder/

tar.bz2

A tar.bz2 uses bzip2 compression on a tarball. Generally the size will be less that a tar.gz file .If you have a .tar.bz2 file , issue this command: ( You need bzip2 installed)

tar -xvjf file-1.0.tar.bz2

If you want to create a tar.bz2 as below.

tar cjvf myfolder.tar.bz2 myfolder/

Tags: