tar is a compression utility that runs on the terminal (shell). This program is especially popular among Linux users.

During programming my little GUI for tar and thereby connected Deal with this program, I've noticed that the help of tar is indeed enlightening, but really not enough. Here for example the description how to extract a file, but not how to extract it in a given directory. Of course you can also filter out this information from the Help but it was not clear in which order information must be done.

To find the solution to my problems, I watched how to solve these on various websites.

In order to spare others this work, I would like to show you with this little tutorial, how to compress and how to decompress a tar archive.


tar cf /path/to/output.tar /path/to/source1 /path/to/source2

To compress is very simple, open a terminal and enters upper chain of command.

With tar cf you specify that you want to create a file.
Then, the output destination and the output file name are set. Then just add all files (with path) which you would like to put it in the archive (separated by a space).

Additionally, compress with BZip 

tar jcf /path/to/output.tar.bzip /path/to/source1 /path/to/source2

To compress the tar archive in addition bzip, we give in the cf option to a j.

Additionally, compress with XZ 

tar Jcf /path/to/output.tar.xz /path/to/source1 /path/to/source2

To compress the tar archive in addition zx, we give in the cf option to a J.

Additionally, compress with GZip 

tar zcf /path/to/output.tar.gz /path/to/source1 /path/to/source2

To compress the tar archive in addition GZip, we give in the cf option to a z.

Additionally, compress with compress 

tar Zcf /path/to/output.tar.cp /path/to/source1 /path/to/source2

To compress the tar archive in addition compress, we give in the cf option to a Z.  

tar -C /path/to/output-folder -xvf /path/to/source.tar

With tar -C /path/to/output-folder you indicate where the file should be decompressed. Then we specify with -xvf /path/to/source.tar that we want to decompress this archive.

decompressing of a single archive entry 

tar -C /path/to/output-folder -xvf /path/to/source.tar entry

As you can see by its very nature is easy, because you need only specify the name of the entry at the end of the command line to decompress.

This entry need, of course, has been determine before. To do this you must read all entries out of the tar- archive. Then copy and past the name of entry you want to decompress.

See a list of all entries from a tar archive

tar -tf /path/to/source.tar

With tar -tf /path/to/source.tar you indicate that you want to read out and display all entries of the archive.

All entries in tar- archives are stored with associated file path, so that you need to decompress a single file, not only must copy the desired file name, you need to copy it together with the corresponding file path.

Tutorial by Christian Albrecht (Lelldorin) September 2013
Made available by BeSly, the Haiku, BeOS and Zeta knowledge base.