How do I use 7-Zip CLI for Windows to create .tar.gz archives?

54,499

Solution 1

Now Windows supports a native tar command:

tar -cvzf output.tar.gz input_dir

https://techcommunity.microsoft.com/t5/containers/tar-and-curl-come-to-windows/ba-p/382409

Found it here.

Solution 2

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

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

The -an switch tells 7-Zip not to parse the archive_name command line parameter that's normally required.

Solution 3

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

Share:
54,499

Related videos on Youtube

f.ardelian
Author by

f.ardelian

Updated on September 18, 2022

Comments

  • f.ardelian
    f.ardelian over 1 year

    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?

  • anion
    anion about 6 years
    note: if you have no 7za.exe in your 7zip-folder you can also use 7zg.exe if available
  • JoL
    JoL over 5 years
    In my case, neither 7za.exe nor 7zg.exe was there, but 7z.exe was.
  • DGoiko
    DGoiko over 4 years
    tar is required becausa a tgz or tar.gz is a tar file which has been gzipped. 7zip just don't have the ability to do all of it in just one step, so you have to pipe the output of the command which tars your files into the one that gzips your tar ^^. This is why when yopu open a tar.gz in 7zip you see a tar file inside.
  • afrazier
    afrazier over 4 years
    @DGoiko I know that part -- I just didn't understand why the archive.tar filename is required when the data is being streamed to stdout.
  • DGoiko
    DGoiko over 4 years
    Oh, I see. I thought that gz needed the internal filename in order to be properly displayed, but maybe I was wrong.
  • kayleeFrye_onDeck
    kayleeFrye_onDeck over 4 years
    I wish the one-liner worked for file-collections instead of just individual files! Thx for the heads up.