The Computer Oracle

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

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping

--

Chapters
00:00 How Do I Use 7-Zip Cli For Windows To Create .Tar.Gz Archives?
00:20 Answer 1 Score 7
00:49 Answer 2 Score 39
01:12 Accepted Answer Score 19
01:23 Thank you

--

Full question
https://superuser.com/questions/339931/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #compression #tar #7zip #gzip

#avk47



ANSWER 1

Score 39


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.




ACCEPTED ANSWER

Score 19


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.




ANSWER 3

Score 7


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