LNXdev.com

TAR Notes

TAR (Tape Archive) is a utility for creating archives with or without compression. TAR was created a long long time ago (probably in the seventies) to write backup-files on a magnetic tape.

Commands

Create an uncompressed archive

This command simply puts several different files in one single file. No compression is used.

$ tar -cvf archive.tar thisfile.txt thatfile.txt somefile.txt

Option 'c' stands for Create, 'v' option is for Verbose, and 'f' is for File. Without file option, the program assumes that you are making a tape archive. So if you don't have a legacy tape recorder, use the file option.

Compress Archive

Archives can be compressed with atleast two different algorithms. Gzip is using DEFLATE the same way as .zip does. Bzip2 uses the more effective Burrows-Wheeler transform, but it is slower than Gzip.

Using Gzip

Remember to add '.gz' at the end of the file. The archive can be compressed without it, but it is difficult to determine the filetype without it.

See also that option 'z' was added here to indicate that we want the file to be compressed.

$ tar -cvzf archive.tar.gz thisfile.txt thatfile.txt somefile.txt

Bzip2

Option 'j' indicates bzip2 compression.

$ tar -cvjf archive.tar.bz2 thisfile.txt thatfile.txt somefile.txt

Extract .tar files

Makes sure you have right options for right filetype. 'x' stands for eXtract.

$ tar -xvf archive.tar
$ tar -xvzf archive.tar.gz
$ tar -cvjf archive.tar.bz2