Trace
Trace

Reputation: 18869

Decompress tar before reading

What difference does the decompress -z flag make when reading a gzipped tar file?

//Without unzipping
sysadmin@localhost:~/Documents$ tar -tf logs.tar.gz                             
logs/                                                                           
logs/access_log.1                                                               
logs/access_log.2                                                               
logs/access_log.3                                                               
logs/access_log.4                                                               

////With unzipping
sysadmin@localhost:~/Documents$ tar -tzf logs.tar.gz                            
logs/                                                                           
logs/access_log.1                                                               
logs/access_log.2                                                               
logs/access_log.3                                                               
logs/access_log.4  

The contents seem to be properly shown in both cases.

Upvotes: 0

Views: 42

Answers (2)

Knud Larsen
Knud Larsen

Reputation: 5899

Year 2004 : From /usr/doc/tar-1.15.1/NEWS , Slackware 10.2 ...

version 1.15 - Sergey Poznyakoff, 2004-12-20

* Compressed archives are recognised automatically, it is no longer
necessary to specify -Z, -z, or -j options to read them. 
( Thus, you can now run `tar tf archive.tar.gz'.)

And year ~2009, the lzma decompress was added to tar, to be recognised automatically : Suffix .xz

Upvotes: 2

Thomas Dickey
Thomas Dickey

Reputation: 54505

When -z was first introduced, it was required when uncompressing archives. Later (perhaps to help with bzip2 support using -j) someone modified GNU tar to make the check and do this automatically. The automatic check is possible because the first few bytes of the file have a distinctive "magic" value.

The change (to tar of course) was fairly recent relative to the -z option: I do not see it explicitly in the changelog, but a comment about "magic" for lzip in 2010 makes it sound relevant, while "compress" is mentioned in the entries for 1997.

Upvotes: 1

Related Questions