How to show unzip progress?

How can I show progress, bar or percentage, when unzipping large files?

unzip zipfile.zip does not show any progress info?


Solution 1:

Without installing anything else, the easiest way is to have it print a dot for every file that is extracted or processed using awk.

unzip -o source.zip -d /destDirectory | awk 'BEGIN {ORS=" "} {print "."}'

If it is a large zip file, then you can elect to print a dot for every 10th or 20th file like this:

unzip -o source.zip -d /destDirectory | awk 'BEGIN {ORS=" "} {if(NR%10==0)print "."}'

Just change the "10" in the NR%10 piece to whatever increment you want.

Alternately, you can install the pv command, which doesn't work really well with unzip, but gives a one liner view that is not totally terrible.

Install pv:

sudo apt install pv

Unzip with pv:

unzip -o source.zip -d /destDirectory | pv -l >/dev/null

This shows output that looks like this:

28.2k 0:00:03 [9.36k/s] [        <=>                       ]

Because of the way that zip files are processed though, it will not show a progress bar in a meaningful way like we would wish.

Solution 2:

Another alternative to show the zip/unzip progress is to use the program 7zip. In the latest version 16.02 (published 2016-05-21) it shows the progress as percentage.

The p7zip packages for version 16.02 are available in the Ubutuntu repository since release artuful/16.10. Older Ubuntu releases have only p7zip version 9.20.1 without progress indicator in the repository. I manually installed the pzip 16.02 version in Ubuntu xenial/16.04 from the bionic repository, there seems to be no other dependencies (p7zip, p7zip-full and p7zip-rar).

7z x source.zip -o/destDirectory

Note that there must be no space between the "-o" and the destination directory name.

Solution 3:

You can create simple wrapper for that:

function punzip {
   unzip $1 | pv -l -s $(unzip -Z -1 $1 | wc -l) > /dev/null;
}

And then use it like follows:

$ punzip file.zip

It might be useful if there are a lot of small files in an archive. But if files are large, it is better to use something like this:

function plunzip {
    for f in $(unzip -Z -1 $1 | grep -v '/$');
    do
        [[ "$f" =~ "/" ]] && mkdir -p ${f%/*}
        echo "Extracting $f"
        unzip -o -c $1 $f \
            | pv -s $(unzip -Z $1 $f | awk '{print $4}') \
            > $f
    done
}

It will show progress bar for each individual file.