Copy progress

I like progress displays on my file operations, in the gui
this is no problem but on the command line most operations don’t
give any useful progress info. So using a tool called pv I wrote a few
little scripts to handle copying stuff with nice progress bars.
This one uses tar to grab a bunch of files or an entire dirtree and
replicate it elsewhere.

#!/bin/bash ARGS=$# # Number of args
passed. DSTDIR=${!ARGS} FILES="" let SIZE=0 until [ -z "$2" ] #
Until all parameters used up… do SRC="$1" shift
SRCDIR="${SRC%/*}" FILES="$FILES ${SRC##*/}" let SIZE+=`du -sb
"$SRC" | awk ‘{print $1}’` done #echo "Source dir = $SRCDIR" #echo
"Dest dir = $DSTDIR" echo "Files = $FILES" PRINTSIZE="$SIZE" if [
$SIZE -gt 1024 ]; then PRINTSIZE=$(echo "scale=3;
$PRINTSIZE/1024.0"
| bc); UNITS="K"; fi if [ $SIZE -gt 1048576 ];
then PRINTSIZE=$(echo "scale=3; $PRINTSIZE/1024.0" | bc);
UNITS="M"; fi if [ $SIZE -gt 1073741824 ]; then PRINTSIZE=$(echo
"scale=3; $PRINTSIZE/1024.0" | bc); UNITS="G"; fi printf "%4.2f%s
(%dbytes)\n"
$PRINTSIZE $UNITS $SIZE (cd $SRCDIR; tar cf – $FILES)
| pv -s $SIZE | (cd $DSTDIR; tar xf –)

and this one just
does a plain copy.

#!/bin/sh PIPECOPYCMD=`which pv` ARGS=$#
# Number of args passed. DEST=${!ARGS} until [ -z "$2" ] # Until
all parameters used up… do SRC=$1 shift PATH=${SRC%/*}
FILENAME=${SRC##*/} if [ -f "$SRC" ]; then if [ ! -e "$DEST" ];
then DESTFILENAME="$DEST" elif [ -d "$DEST" ]; then
DESTFILENAME="$DEST/$FILENAME" else echo "Destination $DEST exists
and is not a directory, aborting"
exit 1 fi #echo "Copy $FILENAME
to $DESTFILENAME"
$PIPECOPYCMD < "$SRC" > "$DESTFILENAME"
else echo "Source $SRC doesn’t exist or is not a file" fi done