Skip to content

Instantly share code, notes, and snippets.

@bhubr
Last active January 2, 2023 13:25
Show Gist options
  • Save bhubr/c76100e0beb4aa884f32f8484146791e to your computer and use it in GitHub Desktop.
Save bhubr/c76100e0beb4aa884f32f8484146791e to your computer and use it in GitHub Desktop.
bzip2 progress bar with pv (Pipe Viewer)

bzip2 progress bar with pv (Pipe Viewer)

Context: I was attempting to compress a fairly big (16Gb) file with bzip2, but had no idea of how much time it would take.

The solution I came up with isn't perfect, since it doesn't show an actual percentage, but it still gives an idea of what's going on, since it prints the compressed file's current size, along with the elapsed time.

Sources

The 1st page gives a few commands that might work on Linux, but don't work on my Mac, though I use Bash.

The solution came from the little screenshot shown on PV's home page:

Pipe Viewer demo

My use case is much simpler than the command demonstrated above. Here's the command, followed by a breakdown:

cat macOS.vdi | bzip2 | pv -cN bzip2 > macOS.vdi.bz2
  1. Dump the file to compress

  2. Pipe it to bzip2

  3. Pipe it to Pipe Viewer. From man pv:

    • -c or --cursor is for "Use cursor positioning escape sequences".
    • -N NAME or --name NAME is for "Prefix the output information with NAME", and is useful if you're monitoring multiple pipe entries with pv, such as in the screenshot above. I could have gone without it.
  4. Last but not least, redirect the compressed data to a file (otherwise you end up displaying a huge amount of garbage in your terminal).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment