Skip to content

Instantly share code, notes, and snippets.

@niraami
Created July 31, 2024 12:56
Show Gist options
  • Save niraami/5fadb004ec9f1b2b760a346a2920b5c3 to your computer and use it in GitHub Desktop.
Save niraami/5fadb004ec9f1b2b760a346a2920b5c3 to your computer and use it in GitHub Desktop.
Get progress of tar extract for use in other commands
#!/bin/sh
tar_path="file.tar.xz"
output_dir="output"
# Use pipe viewer to show progress of extraction
pv --quiet "${tar_path}" | \
tar --extract --xz --directory "${output_dir}" &
# Store ID of the pv process
pv_pid=$(pgrep -ox "pv")
# Print update every second
pv --numeric --interval 1.0 --watchfd $pv_pid:3 2>&1 | \
while read prog; do
echo "Installing root filesystem: ${prog}%"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment