[ale] Neat code clip: cp progress bar

Joey Rutledge joey at joeyrutledge.com
Fri Mar 5 12:00:37 EST 2010


This is really neat.  Typically when I am copying large files and I want to keep up with the progress I will use rsync with the --progress flag.  It's equally as awesome.

Joey

On Mar 5, 2010, at 9:04 AM, Brandon Wood wrote:

> I saw this post on Hacker News today and thought that it deserved to be shared:
> 
> 
> Can you get cp to give a progress bar like wget?
> via Hacker News on 3/4/10
> 
> < zed0> can you get cp to give a progress bar like wget?
> Damn right you can.
> 
> #!/bin/sh
> 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
> }
> In action:
> 
> % cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null
> 76% [===========================================>                    ]
> 
> Comments
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100305/0d024594/attachment.html 


More information about the Ale mailing list