socol 发表于 2013-2-1 11:20:40

计算cp命令的时间和速度

引用自:
http://www.linuxsir.org/bbs/thread49972-2.html
 
#!/bin/sh# Last modified: 2003年07月05日 星期六 00时09分44秒 SOURCE=$1TARGET=$2#CP=./fack_cpCP=cp$CP "$SOURCE" "$TARGET" &CPID=$!isalive(){out=`ps -p $1 2> /dev/null`return $?}while [ 1 ]; do {SSIZE=`/bin/ls -l $SOURCE | gawk "{print \\\$5}"`if [ -f $TARGET ]; thenTSIZE=`/bin/ls -l $TARGET | gawk "{print \\\$5}"`elseTSIZE="0"fiPERCENT=`echo "scale=2; $TSIZE/$SSIZE*100" | bc -l`RATE=`echo "scale=0; 63*$PERCENT/100" | bc -l`BLUE="\\033; do[ $i = $RATE ] && BAR=$BAR"\\033[7;39m"BAR=$BAR" "let i=$i+1doneBAR=$BAR$NORMAILecho -en "\r$BAR ${PERCENT}%"if ! isalive "$CPID"; then echo -en "\n"; exit; fisleep 1}done 
计算多个文件大小:
csize(){C=0INRC=0for file in $1do    INRC=`ls -l $file | awk "{print \\\$5}"`    let C=$C+$INRCdonereturn $C}
页: [1]
查看完整版本: 计算cp命令的时间和速度