2

On AIX 6.1 without GNU Tool installed I have a .tar.gz file.
On Ubuntu I would use the very useful command :

tar xzf myfile.tar.gz

but in this case the z switch is not possible.
I do remeber a long time ago a way to use gzip | tar but I really can't remember.

Can someone help me with that with a command that could work on almost every system even oldfashion unix ?

Kiwy
  • 9,415
  • 13
  • 49
  • 79
  • Older Unixes might have a `gzcat` command, so you can do `gzcat myfile.tar.gz | tar xf -`, but really old ones might not have any gzip components installed at all. – Mark Plotnick Feb 05 '14 at 10:22

2 Answers2

4

Make gzip feed the uncompressed tar archive to tar:

gunzip < myfile.tar.gz | tar xvf -

(note that it's what GNU tar actually does internally, except that it will also report gunzip errors in its exit status).

Use gzip -d if gunzip is not available. You might also have a zcat, but that one may only work with .Z files (compressed with compress instead of gzip).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
  • 1
    You can also replace `tar xvf -` with `pax -rv` (`pax` being the POSIX command to extract `tar` archives) – Stéphane Chazelas Feb 05 '14 at 09:45
  • My gunzip command is pretty old `gunzip 1.2.4 (18 Aug 93) gunzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]` but say you can put a file after gunzip, what's the difference between `gunzip myfile` and `gunzip < myfile` – Kiwy Feb 05 '14 at 09:48
  • @Kiwy, `gunzip f.gz` unzips `f.gz` onto `f`, `gunzip` without argument uncompresses stdin onto stdout. So `gunzip < f.gz` is like `gunzip -c f.gz` with the benefit that it's the shell that opens the file. See also http://unix.stackexchange.com/a/58814/22565 – Stéphane Chazelas Feb 05 '14 at 09:52
  • I guess you should use `gzip -d` instead of gunzip, I already find system that does not has a `gunzip` alias. And also what's the benefit of having the shell opening the file instead of gzip ? – Kiwy Feb 05 '14 at 09:59
  • 1
    @Kiwy, no problem for files called `--help` or `-` for instance, consistent error messages, `gzip` not run if the file can't be open... See http://unix.stackexchange.com/a/58814/22565 – Stéphane Chazelas Feb 05 '14 at 10:16
0

You can unzip separately before the tar.

gzip -d myfile.tar.gz
tar xvf myfile.tar
suspectus
  • 5,890
  • 4
  • 20
  • 26