Home > Blockchain >  Setting Tar compression level in Win10
Setting Tar compression level in Win10

Time:10-11

I created a powershell command in order to compress mdb files from a certain folder. The structure looks like this:

C:\Projects\MySoftware\templates\A\a.mdb
C:\Projects\MySoftware\templates\B\b.mdb
C:\Projects\MySoftware\templates\C\c.mdb

Basically I want that my archive must contains the directories with "templates" as root node. So:

templates\A\a.mdb
templates\B\b.mdb
templates\C\c.mdb

And in PowerShell

powershell -Command "$pa = 'C:\Projects'; Set-Location C:\Projects\MySoftware\; gci -Path templates -Recurse -Include *.mdb  | sort LastWriteTime  | ForEach-Object {  cd 'C:\Projects\MySoftware\'; $fn = $_.Fullname; tar rf BASetupUpdate.tgz $($fn.Replace('C:\Projects\MySoftware\','')) }" 

The tar creates correctly the archive but without compression. I'm struggling with command line and help in order to set the compression level.

CodePudding user response:

You need to add the z option to compress, which cannot be used with r, only c. You would need to make a list of all the things you want to put in the tar file, and use a single invocation of the tar command with all of those names. You cannot incrementally add files to a compressed tar.gz (or .tgz if you prefer) archive. So something like:

tar -czf archive.tgz file1 file2 ... filen

As for the compression level, you can add --option gzip:compression-level=9. However to start, you should leave it at the default level and see if that meets your needs. Higher compression levels can take much more time for a small reduction in size.

  • Related