By default, the tar command archives files, it does not compress them. Tar supports options to compress the resulting archive. Compression can significantly decrease the size of the files. Tarballs are often compressed into one of the following formats:
- gzip format: file.tar.gz or file.tgz
- bzip2 format: file.tar.bz2
- Lempel-Ziv-Markov format: file.tar.lzma
Different tar flags are used to specify different compression formats:
- -j for bunzip2
- -z for gzip
- --lzma for lzma
It is possible to use compression formats without explicitly specifying special options as earlier. tar can compress based on the extension of the output or decompress based on an input file's extension. The -a or - auto-compress option causes tar to select a compression algorithm automatically based on file extension:
$ tar acvf archive.tar.gz filea fileb filec
filea
fileb
filec
$ tar tf archive.tar.gz
filea
fileb
filec