linux下自定义显示文件拷贝进度

1. 首先在终端中执行拷贝命令

cp -a -r /path/to/source/. /path/to/destination/

2. 打开新的终端执行进度显示命令

bash progress.sh /path/to/source/ /path/to/destination/source/

3.j脚本"progress.sh"中内容如下

#!/bin/bash

#src_dir="/path/to/source/"
src_dir=$1

#det_dir="/path/to/destination/source/"
det_dir=$2

echo "src: $src_dir"
echo "det: $det_dir"

src_size=$(du -s "${src_dir}" | awk '{print $1 }')
while true; do
	cur_det_size=$(du -s "${det_dir}" | awk '{print $1 }')

	permill=$(( ((1000 * cur_det_size)) / src_size))
	percent=$(( permill / 10 ))
	per_str=$(( permill % 10 ))

	cdsg=$(( ${cur_det_size} / 1000000 ))
	ssg=$(( ${src_size} / 1000000 ))

	printf "Copying progress: [%5dG/%5dG] [%d.%d%%]\r" ${cdsg} ${ssg} ${percent} ${per_str}

	if [ "${permill}" -eq 999 ]; then
		printf "\nCopying completed.\n"
		break
	fi
	sleep 1
done

你可能感兴趣的:(Linux,linux,服务器,运维)