Last active
December 17, 2015 19:58
-
-
Save CatTail/5663786 to your computer and use it in GitHub Desktop.
cp command with progress bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cp_p() | |
| { | |
| strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \ | |
| | awk '{ | |
| count += $NF | |
| if (count % 10 == 0) { | |
| percent = count / total_size * 100 | |
| printf "%3d%% [", percent | |
| for (i=0;i<=percent;i++) | |
| printf "=" | |
| printf ">" | |
| for (i=percent;i<100;i++) | |
| printf " " | |
| printf "]\r" | |
| } | |
| } | |
| END { print "" }' total_size=$(stat -c '%s' "${1}") count=0 | |
| } | |
| # 输出 | |
| # cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null | |
| # 76% [===========================================> ] | |
| # 其他工具 | |
| # pv | |
| # rsync | |
| # 相关链接 | |
| # https://chris-lamb.co.uk/posts/can-you-get-cp-to-give-a-progress-bar-like-wget | |
| # http://askubuntu.com/questions/17275/progress-and-speed-with-cp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment