From LinuxReviews
Jump to: navigation, search

tar (derived from tape archiver) is The GNU version of the tar archiving utility and also the file format it uses.

It is used to compress and decompress archives of files. The format was standardized by POSIX.1-1988 and later POSIX.1-2001.


[edit] History

tar was developed as a raw format which was meant to be used for tape backup and other sequential access devices for backup purposes.

It is now used to collate collections of files into one larger file container for archiving and distribution while preserving file system information such as user and group permissions, dates, and directory structures. tar typically pipes the file container to another compression utility such as lzma or bzip2.

[edit] Compression algorithms

Tar can be used together with gzip, bzip2, lzma and compress.

gzip is the fastest compression technology. It is designed for speed.

bzip2 is slightly slower and compresses slightly better.

lzma is extremely slow and takes ages compared to gzip. It does compress signifficantly better than gzip and also better than bzip2.

[edit] TIFF images

natvetkas1 is a 213 MB big folder with 213 large black and white TIFF images.

  • tar cfvz (gzip) is fast and creates a 28 MB large tarball.
  • tar cfvj (bzip2) creates a 24 MB large archive.
  • tar cfvz (lzma) takes longer and creates a 18 MB large archive.

lzma, with 18 MB, creates a 10 MB smaller image than gzip (28 MB). It does compress better at the cost of more than double the time used to create the archive.

[edit] Softwarez

Already compressed files and softwarez may not compress anything noticable regardless of what compression technology is used.

OFFICE2003 has 401 MB of Microsoft Softwarez. The installation files are all stored as ".CAB" files.

  • gzip stores OFFICE2003.tar.gz using 393M
  • lzma uses days longer to store the OFFICE2003.tar.lzma warez using 391M.

The insignifficant 2M saved lzma storage space may not be worth the months longer lzma compression times.

[edit] Typical tar usage

Pure tar archives are created with the cf switch.

-c create a new archive
-f use archive file or device F (default "-", meaning stdin/stdout)
tar cf container.tar files/*.txt stuff/*.jpg

It's generally smart to add v for verbose.

tar cfv container.tar files/*.txt stuff/*.jpg

You typically want to pipe the archive through some kind of compression technology as tar does not compress, it just stores in containers.

A 241 MB folder full of secret documents will be tarred into a 241 MB container. Add j for bzip2 compression, tar cfvj, and you could get a 20 MB container with the same secret documents.

[edit] Compress

-c create a new archive
-f use archive file or device F (default "-", meaning stdin/stdout)
-v verbosely list files processed


tar cfvz archive.tar.gz folder1/ folder2/
-z filter archive through gzip, use to decompress .gz files


tar cfvj archive.tar.bz2 folder1/ folder2/
-j filter archive through bzip2, use to decompress .bz2 files


tar cfva archive.tar.lzma folder1/ folder2/
-a filter archive through lzma, use to decompress .lzma files

Use -C to extract to a specific folder:

tar -xvf eglinux.tar.gz -C ~/stuff/new/software

[edit] Decompress

-x decompress archive


tar xfvz archive.tar.gz


tar xfvj archive.tar.bz2


tar xfva archive.tar.lzma

Personal tools
hardware tests
Privacy policy
linux events


linux newz | random page | poetry | free blog