新建CP.sh,用法与cp命令一样:CP.sh 源文件 目标文件
#!/bin/bash
PARAM_LIST=$*
PARAM_NUM=$#
TOTAL_SIZE=0
for((i = 0; i < PARAM_NUM - 1; i++))
do
[ ! -r $1 ] && echo "Cannot read $1." && exit 1
SIZE=`du -s $1 | awk '{print $1}'`
((TOTAL_SIZE = TOTAL_SIZE + SIZE))
shift
done
TARGET=$1
START_TIME=`date +%s.%N`
cp -a $PARAM_LIST &
echo -ne "Total size: $TOTAL_SIZE KB - %"
while true
do
LEN_PERCENT=${#PERCENT}
for((i = 0; i <= LEN_PERCENT; i++))
do
echo -ne "\b"
done
COPIED=`du -s $TARGET | awk '{print $1}'`
((PERCENT = COPIED * 100 / TOTAL_SIZE))
echo -ne "$PERCENT%"
((PERCENT == 100)) && END_TIME=`date +%s.%N` && break
done
MB_SECOND=`echo $TOTAL_SIZE/1024/\($END_TIME-$START_TIME\)|bc`
echo " - SPEED: $MB_SECOND MB/s"