Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to estimate the extracted size of a tar.gz file without extracting it in PowerShell 7 (Windows 11)?

I have a tar.gz file that is about 1.39GB. I want to estimate the unzipped size before I actually extract it to avoid filling up my disk. This is for my work and I can only use my work PC (Windows 11) for it. I’m using PowerShell 7. What is the command to accomplish this?

I found many answers under unix/linux, like this one.

I guess in unix/linux, the solve is tar -cz data_dir | wc -c

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But what is the equivalent in PowerShell 7 (Windows 11)?

>Solution :

You can use the built-in tar.exe to list the content of your gzip archive:

tar.exe -t -v -f test.tar.gz

You can then parse the output and add up the sizes:

$tarOutput = tar.exe -t -v -f test.tar.gz
$size = ($tarOutput | %{(-split $_)[4]} | Measure-Object -Sum).Sum
$size
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading