Here’s a basic bash script that will determine the estimated time it will take to compress a directory using .tar.gz.
NOTE: If you have a basic linux installation then you will need to install the pv utility for monitoring piped data.
# install on fedora/centos
$: yum install pv
# install on ubuntu/debian
$: apt-get install pv
It will show the following:
• It calculates how large the file will be
• States how long it took to compress the directory and files
• Provides a progress bar
• Displays the eta
Download the bash script and review the code below. Control + click to download on Mac or Right click on Windows
Download Shell script: tar-eta.txt ( Rename file with .sh suffix or trying copying and pasting from file )
#!/bin/bash
usage="$(basename "$0") [-h] -- 1st argument is the name of the compressed directory without the .tar.gz at the end, 2nd argument is the directory to compress"
while getopts ':h' option; do
case "$option" in
h) echo ""
echo "$usage"
echo ""
exit
;;
esac
done
echo "#############################"
echo ""
echo "This script allows you to compress files in the filename.tar.gz format"
echo ""
echo "This script will provide an eta for when the file will be done compressing"
echo ""
echo "1st argument is the name of the compressed directory without the .tar.gz at the end"
echo ""
echo "2nd argument is the filename for the directory to be compressed, enter filename only ( no .tar.gz in name )"
echo ""
echo "The number of arguments you supplied is: $#"
echo ""
echo "##############################"
echo ""
if [ -z "$1" ]
then
echo "*************** Error: As your first argument please enter a source directory to compress *****************"
echo ""
exit
fi
if [ -z "$2" ]
then
echo "*************** Error: As your second argument please enter a filename for the compressed file, do not add .tar.gz to the end of the file. *****************"
echo ""
exit
fi
####
# NOTE: add a check to see if the source directory exists!
####
if [ ! -d "$1" ]
then
echo ""
echo "Source directory does not exist, please try again"
echo ""
fi
tar cf - $1 -P | pv -s $(du -sb $1 | awk '{print $1}') | gzip > $2.tar.gz