How can I use the 7-Zip CLI (7za.exe) on Windows to create .tgz archives, as I use tar zcvf archive.tgz source_files on Linux?

migrated from stackoverflow.com Sep 26 '11 at 11:30

This question came from our site for professional and enthusiast programmers.


If you'd like to do it in a one-liner:

7za.exe a -ttar -so archive.tar source_files | 7za.exe a -si archive.tgz

I'm not sure why the archive.tar is required in the first part, but it is. It doesn't even need to end in .tar, it just needs an archive name to use.

  • note: if you have no 7za.exe in your 7zip-folder you can also use 7zg.exe if available – anion Mar 1 '18 at 16:16
  • 1
    In my case, neither 7za.exe nor 7zg.exe was there, but 7z.exe was. – JoL Nov 1 '18 at 16:16

If you're just compressing 1 file into the tarball then 7za a archive.tgz source_file will work.

If you want to add lots of files to the tar then you need to do it in two steps: Create the tar 7za a archive.tar source_files Then compress it 7za a archive.tgz archive.tar

And, optionally, delete the 'temporary' tar del archive.tar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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