3

I would like to skip a large gzip file when I extract a tar file, but everytime tar starts to gunzip it to look inside it seems.

Even when I just try to peek inside tar seems to start gunzipping it, for example:

tar -tvf my.tar.gz --exclude="huge_mysql_file.gz"

Any tips how to skip entirely that file? I see gzip running when tar gets to that gz file.

5
  • 2
    why do you think that tar is gunzipping the file?
    – miracle173
    Commented Sep 30, 2012 at 7:27
  • Try gzip -dc my.tar.gz | tar tf -.
    – Thor
    Commented Sep 30, 2012 at 8:04
  • It always gets stuck at a large gz file, and when I look at top in another shell window I can see gzip running next to tar.
    – giorgio79
    Commented Sep 30, 2012 at 9:16
  • I don't really understand you problem here, but it seems that inside that .tar.gz are other .gz files? If that's the case, then the archive is wrong to begin with. a .tar.gz file, is a gziped tar-file, which contains a collection of uncompressed files. Everything else is pretty much done by an idiot.
    – polemon
    Commented Sep 30, 2012 at 12:56
  • 1
    As others have pointed out, tar has to read .tar.gz files sequentially, so it can't find out what's after "huge_mysql_file.gz" without reading it in to get to the next file in the archive. If you need to view the contents of a .tar.gz file frequently, you can always create a text file containing the files list. e.g. tar tvzf my.tar.gz > my.tar.gz.list. you can then read that .list file with less or grep it etc.
    – cas
    Commented Sep 30, 2012 at 22:43

1 Answer 1

7

my.tar.gz is a gzipped tar file. tar ist short for 'tape archive'. So the file my.tar.gz has to be unzipped by gzip -d before the tar file can be read. There is no random access to the content of a gzip file. I do not really know the gzip file format but at least there is no option for gzip to do this. The 'gzip -d' started by tar to unzip the my.tar.gz file is the gzip you can see. tar does not decompress the file huge_mysql_file.gz but it has to read (and ignore) the file huge_mysql_file.gz because this is provided by the pipe to gunzip.

if the tar file is not gzipped and you list its content like in

tar -tvf my.tar --exclude="huge_mysql_file.gz"

only the header of huge_mysql_file.gz in the archive must be read to know its size. Then tar can skip the file without reading it and continue on the following file.

3
  • Note that tar cannot do sequential access in this case because the archive is read from a pipe (from gzip), but for a tar in a regular file (uncompressed), it will not read the full content and will skip to the start of each file header in that archive (for -t to display the content) Commented Sep 30, 2012 at 21:50
  • thx to @sch: I will check this and adjust my answer as soon as possible
    – miracle173
    Commented Oct 1, 2012 at 6:08
  • thx again @sch: I rewrote the post and hope now there are no more errors
    – miracle173
    Commented Oct 7, 2012 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .