Why are tar and gzip almost always used together, and not just gzip? Is there any advantage to that method?
|
feedback
|
migrated from stackoverflow.com Mar 2 '11 at 3:47
This question came from our site for professional and enthusiast programmers.
|
TAR creates a single archived file out of many files, but does not compress them. Format Details
GZIP compresses a single file into another single file, but does not create archives. File Format
| |||||||||||||||||||
feedback
|
|
Gzip / Bzip2 are stream compressors. They compress a stream of data into something smaller. They could be used on individual files, but not on groups of files on their own. Tar on the other hand has the ability to turn a list of files, with paths, permissions and ownership information, into a single continuous stream - and vice versa. That's why, to archive files (and if one needs compression as well), one usually uses tar + some compression method. | |||
|
feedback
|
|
Tar is in charge of doing one and only one thing well: (un)archiving into(out of) a single archive file. Of what? Of one and only one thing: a set of files. Gzip is in charge of doing one and only one thing well: (un)compressing. Of what? Of one thing and one thing only: a single file of any type... and that includes a file created with tar. It goes back to the UNIX philosophy of pipelining, the underlying "pipe and filters" architecture ; the treatment of everything as a file and the sound architectural goal of "one-thing-does-one-thing-only-and-does-it-well" (which results in a very elegant and simple plug-n-play of sorts.) In its simplicity, it is almost algebraic in nature (a hefty goal in systems design). And that is no easy feat. In many ways (and not without its flaws), this is almost a pinnacle in composability, modularity, loose coupling and high cohesion. If you understand these four (and I mean really understand), you understand, it will be obvious why tar and gzip work like that in pairs. | |||||||
feedback
|
|
First of all, TAR wasn't created to create file archives. It's Tape ARchiver. It's job is to write out or load in an archive to/from tape. The -f option makes it use a file as "virtual tape", which can then be compressed by another program. In fact, such compression happens on real-world tapedrives as well. Of course, the philosophy of using one program to do it well also counts in this case, but one might miss why TAR archives are structured as a stream instead of directory of contents + contents. | |||||
feedback
|