Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add progress bar to a somearchive.tar.xz extract

Tags:

bash

tar

I'd like to print at the very least print # files extracted, from running a tarball extract

xz -dc /path/to/somearchive.tar.xz | sudo tar xvpf - -C /path/to/some_directory

I was thinking of using the "\r" as mentioned in this question, for instance

num=0
when [\n received]
    num=$(($num + 1))
    echo -ne "$num files extracted \r"
end when

my bash skills fail me.

like image 405
GlassGhost Avatar asked Oct 15 '13 02:10

GlassGhost


People also ask

How do you use Extrac on tar XZ?

xz file simply right-click the file you want to extract and select “Extract”. Windows users need a tool named 7zip to extract tar. xz files. For more verbose output, use the -v option.

Can 7zip extract tar XZ?

The compression algorithm is especially effective as it is faster than standard ZIP and GZip formats. Now, compressing and decompressing Tar. xz files is a relatively easy process. However, when extracting them on Windows, you will have to download third-party decompression software like 7zip or WinZip.

What is XVF in tar?

xvf is the Unix-style, short method to implement –extract –verbose –file. So, x stands for extracting the archive, v for displaying Verbose information, and f for specifying a filename.

How do I extract the contents of a tar file?

Simply right-click the item you want to compress, mouseover compress, and choose tar. gz. You can also right-click a tar. gz file, mouseover extract, and select an option to unpack the archive.


1 Answers

Using pv to pipe the file to tar.

  1. Firstly, you'll need to install pv, which on macOS can be done with:

    brew install pv
    
  2. Pipe the compressed file with pv to the tar command:

    pv mysql.tar.gz | tar -xz   
    

Here's the sample output of this command:

Sample output

For those curious, this works by pv knowing the total file size of the file you pass it and how much of it has been "piped" to the tar command. It uses those two things to determine the current progress, the average speed, and the estimated completion time. Neat!

like image 193
Joshua Pinter Avatar answered Oct 05 '22 22:10

Joshua Pinter