1

Say I have a file called package.tar.gz Then I do: cat package.tar.gz | gzip -d | tar tvf - and it shows me the list of files in my tar archive.

However if I do: gzip -d package.tar.gz | tar tvf - It says tar: This does not look like a tar archive

I don't understand why that is. If the result of gzip -d in the first case returns output which can be interpreted as a tar archive, why won't it work in the second case?

I have seen Autotools - tar This does not look like a tar archive but I'm not convinced that it's an issue with tar in my case since the first command works...

Community
  • 1
  • 1

4 Answers4

1

It looks to me like you're not passing the -d option in the second case. from the manpage,

Compressed files can be restored to their original form using gzip -d or gunzip or zcat.

What's probably most appropriate for that style is zcat which is just what it sounds like - gunzip + cat.

erik258
  • 14,701
  • 2
  • 25
  • 31
1

The GNU tar will directly decompress the file:

tar -xf package.tar.gz

It automatically detects which decompressor to use (gzip, bzip2, xz, lzip, etc).

If your tar won't handle the decompressions, then gzip -cd decrypts to standard output:

gzip -cd package.tar.gz | tar -xf -

The -c option means read from standard input or write to standard output (in this case, write); the -d option means decrypt. You could also use gunzip -c in place of gzip -cd. This is 'standard' behaviour for compression programs.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

Is this what you want to do?

gunzip -c package.tar.gz | tar xvf -

Or

gzip -cd package.tar.gz | tar xvf -
jgr
  • 3,914
  • 2
  • 24
  • 28
  • Oh, yes the second one works! Why do you use the < though? gzip -d package.tar.gz works just fine on its own but doesn't work combined with the pipe... – user2193268 Mar 23 '14 at 01:02
0

Basically,

gzip -d package.tar.gz

will not output to standard out, which

tar tvf - 

expects. The result of

gzip -d package.tar.gz

is that the file is unzipped as a side effect. Need to use

gzip -dc package.tar.gz | tar tvf - 

to get the desired effect.