6

I don't understand the use of TAR. My understanding is it pulls together many files into one file. But doesn't putting files in a folder do this?

Using ZIP, I put files I want to archive in a folder and then compress the folder.

Do I also get an archive if I put files I want to archive in a folder and then compress with Bzip2?

1
  • You can't compress a folder with bzip2. bzip2 only operates on individual files
    – tumbleweed
    Dec 24, 2011 at 14:00

3 Answers 3

9

tar lives up to its name "Tape ARchiver". It takes a directory tree, and writes it out to a single file (which could be a tape drive), preserving the directory structure and metadata.

So, yes, very similar to zip, although without built-in compression, and with a full understanding of unix metadata.

The unix philosophy is that each tool should do one thing, and do it well. Tar can archive a directory, and the you can compress the archive with a compression tool like gzip, bzip2, or xz.

1
  • 3
    Of course, tar has options to automatically pass the output to the compressor for you: -z for gzip, -j for bzip2, and -J for xz.
    – psusi
    Dec 24, 2011 at 19:57
6

tar and zip perform similar functions. tar has been the default method of archiving in linux forever.

tar, by itself, does not have compression, however you may select a number of compression methods when you make the archive.

The general syntax for tar is

tar archive_name file_to_archive
tar archive_name directory_to_archive

You may specify a method of compression

-a = will determine method from the suffex you give the archive
-j = bzip2
-J = xz
-z = gzip
-p = preserve permissions
-c = create an archive
-x = extract the archive
-C = specify a destination for extracted files
-t = list the contents

The major advantage of tar over zip is that it preserves linux permissions.

That is just a brief review of the basic options, you can add or remove files from the archive an all sorts of things.

see man tar or any of the online tutorials for options.

1
  • 1
    It also tends to get better compression ratios than zip since zip compresses only 32kb at a time, though that makes it ( zip ) faster at extracting an individual file from the middle of the archive, and zip can list the contents faster than tar since it doesn't need to read the whole archive just to find out what files are in it.
    – psusi
    Dec 24, 2011 at 20:02
2

Tar does more then just grouping files together (as if in a folder).

  1. Compression, if the files are compressible.

  2. Preserving permissions.

You can archive folders and files, and yes, you'll get archives in both cases.

Needless to say that tar can do lots of other things, just check out man tar.

3
  • 2
    My understanding is that TAR does not compress. So (if true) then there is one difference between TAR and "files in a folder" = TAR preserves permissions?
    – Sam
    Dec 24, 2011 at 13:51
  • @Sam - with the z option, tar does the compression as well: tar cvzf name.tgz *. However, the basic tar probably just invokes the compress program as a post-processor.
    – ysap
    Dec 24, 2011 at 18:34
  • 1
    @Sam, files in a folder are just normal files. Both tar and zip take files in a folder and put them in a single file.
    – psusi
    Dec 24, 2011 at 19:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .