If I make a .tar.gz via

tar czvf - ./myfiles/ | pigz -9 -p 16 > ./mybackup.tar.gz,

Can I safely unzip an already gzip'd file ./myfiles/an_old_backup.tar.gz within the ./myfiles directory via

gzip -d mybackup.tar.gz
tar -xvf mybackup.tar
cd myfiles
gzip -d an_old_backup.tar.gz
tar -xvf an_old_backup.tar

? And can one do this recursive compression safely ad infinitum?

  • Your question seems corrupted, did you proof read it? Are you asking is it safe to zip/tar a zip/tar file? (I.e. will there be data lose if I do this?) – ctrl-alt-delor Feb 10 '17 at 16:56
  • Notes: (1) tar f - is weird, you could just omit the f switch, (2) the calls to gzip seem extraneous; tar xz will take care of unzipping by itself. – dhag Feb 10 '17 at 17:01
  • The calls to gzip are required when using pigz in the initial compression. Otherwise the tar extraction fails. – khaverim Feb 10 '17 at 17:03
  • 1
    I meant the calls to gzip when extracting; gzip -d mybackup.tar.gz will delete mybackup.tar.gz, causing the following tar ... mybackup.tar.gz to fail. – dhag Feb 10 '17 at 17:07
  • 1
    But then you should also get rid of the z, since the input to tar is not gzip-compressed anymore :) – dhag Feb 10 '17 at 17:10

If your question can be rephrased as "is it OK to have compressed archives within compressed archives?", then the answer is "yes".

This may not be the most convenient (as you note, you will have to run tar several files to get everything unpacked), and applying compression to data that has already been compressed may not yield an additional reduction in size, but it will all work.

  • That's a good rephrase but I want to make sure this is true even using tar, gzip and pigz in tandem. – khaverim Feb 10 '17 at 17:01
  • The answer is still "yes". pigz is meant to produce the same output as gzip, just using computing resources differently. – dhag Feb 10 '17 at 17:07
  • I tried one recursion and it worked... Probably should have just tried first, thanks for answer – khaverim Feb 10 '17 at 17:10
tar czvf - ./myfiles/ | pigz -9 -p 16 > ./mybackup.tar.gz

is the equivalent of

tar cvf - ./myfiles/ | gzip | pigz -9 -p 16 > ./mybackup.tar.gz

You're not obtaining a tar.gz but a tar.gz.gz, an archive compressed twice, not a compressed archive of compressed files.

That is pointless. Compressed output is not compressible. You won't get any significant space gain by compressing twice. And for extracting, you'd need to decompress twice as well with

gunzip < mybackup.tar.gz | gunzip | tar xf -


gunzip < mybackup.tar.gz | tar xzf -

If you want to use pigz instead of plain gzip for the compression, just do:

tar cvf - ./myfiles/ | pigz -9 -p 16 > ./mybackup.tar.gz

Which you can uncompress with tar zxvf mybackup.tar.gz

Also note that you should never have to uncompress a tar.gz file and store the uncompressed version on disk. The whole point of compressors like gzip/pigz, bzip2/pbzip2, xz/pixz is that they can work on streams, you just insert them in a pipeline.

  • I see. I was being excessive with the double-zippin'. ty – khaverim Feb 10 '17 at 17:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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