Does tar actually compress files, or just group them together?

I usually assumed that tar was a compression utility, but I am unsure, does it actually compress files, or is it just like an ISO file, a file to hold files?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Tar is an archiving tool (Tape ARchive), it only collects files and their metadata together and produces one file. If you want to compress that file later you can use gzip/bzip2/xz. For convenience, tar provides arguments to compress the archive automatically for you. Checkout the tar man page for more details.

Method 2

tar produces archives; compression is a separate functionality. However tar alone can reduce space usage when used on a large number of small files that are smaller than the filesystem’s cluster size. If a filesystem uses 1kb clusters, even a file that contains a single byte will consume 1kb (plus an inode). A tar archive does not have this overhead.

BTW, an ISO file is not really “a file to hold files” – it’s actually an image of an entire filesystem (one originally designed to be used on CDs) and thus its structure is considerably more complex.

Method 3

The original UNIX tar command did not compress archives. As was mentioned in a comment, Solaris tar doesn’t compress. Nor does HP-UX, nor AIX, FWIW. By convention, uncompressed archives end in .tar.

With GNU/Linux you get GNU tar. (You can install GNU tar on other UNIX systems.) By default it does not compress; however, it does compress the resulting archive with gzip (also by GNU) if you supply -z. The conventional suffix for gzipped files is .gz, so you’ll often see tarballs (slang for a tar archive, usually implying it’s been compressed) that end in .tar.gz. That ending implies tar was run, followed by gzip, e.g. tar cf - .|gzip -9v > archive.tar.gz. You’ll also find archives ending in .tgz, e.g. tar czf archive.tgz ..

Edit: www.linfo.org/tar.html reminded me that GNU tar supports much more functionality than merely compressing with gzip, and it reminded me that the suffixes are more than plain conventions. They have built-in semantics. It also supports bzip2 (-j for .bz2) and old compress (-Z for .Z). Then I looked at the man page and was reminded that -a automatically maps your desired compression method based on suffix.

One other nit. As the Linux tar man page says, GNU produces info pages, not man pages, so to learn all about GNU tar, run info tar.

Method 4

tar utility does not compress until you give argument to do so [tar -z file name].


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x