OK I don't really have a good title yet but I figure I can post works in progress and other tips I've come across or other interesting things.
Tar progress bar for scripts
I use SlackBuild scripts a lot and the typical standard is to use the verbose option to print all the file names as they are extracted. This is annoying. However there really isn't a progress bar for tar... or is there?!
Well if we knew the number of files in the tar file we could probably calculate the percentage progress of the file list, but that would take too much time... Thankfully there is --checkpoint
So, outside the script, you find the general number of files that the archive is going to have.
Then we divide this number by our standard console width and add in the script as follows:
for webkit, this was roughly 11120 / 78 = 142 and the output is:
Now doesn't that look nicer than the annoying file list that nobody cares about?... Yes I know the line of dots doesn't go to the end. It's not exact and you will have to tweak the number a bit.
OK OK I hear your argument. "--checkpoint only a gnu/tar option." To which I reply, "It's a gnu/linux OS, not BSD or other." I'm not trying to be compliant with anything other than a recent gnu/linux OS.
Well if we knew the number of files in the tar file we could probably calculate the percentage progress of the file list, but that would take too much time... Thankfully there is --checkpoint
So, outside the script, you find the general number of files that the archive is going to have.
Code:
# Don't do this in your script. It takes too long on really large archives. tar --list -f <compressed tar file> | wc -l
Code:
# 76 dashes and 2 pipes for our standard console width echo "|----------------------------------------------------------------------------|" # please note the dot in the checkpoint. This is so it outputs only a dot every # specified number of files. tar xf <compressed tar file> --checkpoint=.<total files divided by 78> # start a new line for niceness of display echo ""
Code:
|----------------------------------------------------------------------------| ........................................................................
OK OK I hear your argument. "--checkpoint only a gnu/tar option." To which I reply, "It's a gnu/linux OS, not BSD or other." I'm not trying to be compliant with anything other than a recent gnu/linux OS.
Total Comments 0