While the pv
solution shows progress nicely, it doesn't show what files are extracted whereto. The --checkpoint=.100
option shows the files and indicates that it's working, but doesn't show progress.
On the Tar Checkpoints page I found some information about the --checkpoint-action
option, which is able to execute some bash magic for every checkpoint. Knowing that a checkpoint is created every 20 blocks of 512 bytes (at least that's the default, see man tar
), It's possible to get the progress based on the current block and the original size.
The snippet below can be saved as a bash file (or put into a bash function):
archive="$1"
originalsize=$(file $archive | rev | cut -d' ' -f1 | rev)
step=100
blocks=$(echo "$originalsize / 512 / 20 / $step" | bc)
tar -xvz --checkpoint=$step --totals \
--checkpoint-action="exec='p=\$(echo "\$TAR_CHECKPOINT/$blocks" | bc -l);printf \"%.4f%%\r\" \$p'" \
-f $archive
Then using it is very straightforward:
bash tarprogress.sh your.archive.tgz