例子,shell/ target=_blank class=infotextkey>shell脚本复制文件,容易较大的文件会显示复制进度,以百分比显示,与wget下载命令的进度显示很相似。
代码:
#!/bin/sh
#from: www.yuju100.com
strace -q -eread cp -- "${1}" "${2}" 2>&1
| linuxjishu/13830.html target=_blank class=infotextkey>awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
for (i=0;i<=percent;i++)
printf("=");
printf(">");
printf ("%2.0f%%r", percent);
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0