LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > Lumak's Guide to Random Things
User Name
Password

Notices


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.
Rate this Entry

Tar progress bar for scripts

Posted 10-20-2010 at 01:55 AM by lumak
Updated 10-20-2010 at 01:57 AM by lumak

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.
Code:
# Don't do this in your script.  It takes too long on really large archives.
tar --list -f <compressed tar file> | wc -l
Then we divide this number by our standard console width and add in the script as follows:

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 ""
for webkit, this was roughly 11120 / 78 = 142 and the output is:
Code:
|----------------------------------------------------------------------------|
........................................................................
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.
Views 7629 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:36 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration