Progress bar with cp
Today I found a very informative post on how to get a progress bar with the cp command in Linux.
You can find that blog post here. But I’ll repost the information here in case his blog ever disappears.
With the following bash script:
#!/bin/sh
cp_p()
{
set -e
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
}
You will get a progress bar like this:
% cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null
76% [===========================================> ]








It’s not a bash script..
Comment by Lamby — January 25, 2008 @ 10:32 am
Will this work with scp also?
Comment by TheBlackCat — February 4, 2008 @ 3:14 pm
John,
Sorry to contact you this way, but I came across your profile on LinkedIn and wanted to see if you (or someone you know) might be interested in learning about a Linux Kernel Developer position that I am recruiting for. If so, you can email me at trevor@whoblue.net.
Thanks,
Trevor Smith
Comment by Trevor Smith — May 12, 2008 @ 11:41 am