Most source files (and sometimes programs and files) that you download from the Internet come packaged as “tarballs”. A tarball is an archive file similar to “zip” files in Windows world. The name comes from its original purpose, storing data in Magnetic Tapes (Tape ARchiver), and usually has the .tar extension. When it is compressed, it is .tar.gz (sometimes shortened to .tgz) or .tar.bz2. Extracting the files from the tarball is called “untaring”.
Managing tarballs can be easily done in most file managers (Thunar in antiX MX, for example, or SpaceFM in antiX) for everyday use, but on the command line the utility tar is used.
- Create a gzip compressed tar file
tar -czf newFileName.tar.gz file1 file2 folder1 etc
- Create a bzip2 compressed tar file
tar -cjf newFileName.tar.bz2 file1 file2 folder1 etc
The tar.gz and tar.bz2 extensions are merely conventions, they aren’t absolutely necessary. bzip2 provides better compression ratio than gzip, however gzip is faster.
- Extract a compressed tar.gz or bzip2 file
tar -xvf filename.tar.gz
tar -xvf filename.tar.bz2
To untar multiple files use this command:
for i in *.tar; do tar xvf $i; done
or for .bz2 files:
for i in *.bz2; do tar xvf $i; done