Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract .tar.gz by command line with progress in windows

I'm trying to extract a tar.gz file in windows using command line and get a progress precentage. First, I want it to be extracted in a single operation (not extract the tar and then untar). The only two tools that can do it I found are Tartool and 7zip. Tartool is good (also easy to detect errors) but has no progress. 7zip you must use the strem in and out, so I created a basic bat file:

cd /d %~dp0
7z.exe x "%1" -so | 7z.exe x -aoa -si -ttar -o"%2"

It works fine with extraction, but the progress remains still 0% during the whole process (I tried running from cmd), I think that's because of stream input and output.

I know that winrar can show a progress percentage even when doing this operation (extract a tgz file), so how can I achive the same result?

The closest I can get to my goal is getting the output dir size and dividing by the uncompressed size of tar.gz file (got through 7z.exe l function). Also the progress is not linear, it changes only when a file is extracted (EG if my targz contains 2 very big files, I can only get 0%, 50% and 100% during extraction)

like image 329
Franz Tesca Avatar asked Nov 30 '25 15:11

Franz Tesca


1 Answers

Many programmers have installed Git for Windows. It comes with a fine Bash environment which also contains GNU tar. Using the regular tar command you can easily use options for checking progress, especially the --checkpoint and --checkpoint-action options. Play around with them, you can do nice things with them, from simple stuff like

tar --checkpoint=1 --checkpoint-action=dot -xzf my-archive.tar.gz
tar --checkpoint=1 --checkpoint-action=echo -xzf my-archive.tar.gz

to more advanced stuff like

tar --checkpoint=1 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r" -xzf my-archive.tar.gz
tar --checkpoint=1 --checkpoint-action=ttyout='%{%Y-%m-%d %H:%M:%S}t (%d sec): #%u, %T%*\r' -xzf my-archive.tar.gz

if you do not like scrolling messages but output being updated in-line - or whatever you please. You can even run any shell command you like.

like image 164
kriegaex Avatar answered Dec 02 '25 05:12

kriegaex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!