Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
Also on SuperUser. –  allquixotic Apr 30 at 17:38

3 Answers 3

up vote 32 down vote accepted

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.

share|improve this answer
7  
A slight clarification on the answer. It is GNU tar that provides those extra compression arguments. For example, Solaris tar does not provide arguments for compression. –  Tero Kilkanen Apr 29 at 22:20
4  
oooh, that's why I keep seeing thing.tar.7z –  Mooing Duck Apr 30 at 0:34
    
BSD tar provides an argument for compression as well, though it only accepts z and determines the compression method based on the extension, whereas GNU tar has separate zZjJ arguments for the different compression methods. –  wingedsubmariner Apr 30 at 0:59
1  
Just read the BSD tar manpage, and it turns out I was mistaken, BSD tar uses separate zZjJ for compression just like GNU tar. However, it does automatically detect compression when decompressing though, whereas GNU tar expects zZjJ then also. –  wingedsubmariner Apr 30 at 3:10
5  
@wingedsubmariner: no; modern-ish versions of GNU tar decompress automatically without requiring the -zZjJ options. –  Jonathan Leffler Apr 30 at 4:02

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.

share|improve this answer
    
Actually an empty file will not consume 1kb. A 1-1023 byte file will. –  psusi Apr 30 at 3:28

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.