I saw this post on Hacker News today and thought that it deserved to be shared:<div><br></div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div style="font-family: sans-serif; overflow-x: auto; overflow-y: auto; width: 769px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; ">
<h2 style="margin-top: 0.25em; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div><a href="http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/" target="_blank" style="color: rgb(42, 93, 176); ">Can you get cp to give a progress bar like wget?</a></div>
</h2><div style="margin-bottom: 0.5em; ">via <a href="http://news.ycombinator.com/" target="_blank" style="color: rgb(42, 93, 176); ">Hacker News</a> on 3/4/10</div><br><pre style="white-space: pre-wrap; word-wrap: break-word; ">
< zed0> can you get cp to give a progress bar like wget?
</pre><p>Damn right you can.</p><div><pre style="white-space: pre-wrap; word-wrap: break-word; "><span>#!/bin/sh</span>
cp_p<span>()</span>
<span>{</span>
strace -q -ewrite cp -- <span>"${1}"</span> <span>"${2}"</span> 2>&1 <span>\</span>
| awk <span>'{</span>
<span> count += $NF</span>
<span> if (count % 10 == 0) {</span>
<span> percent = count / total_size * 100</span>
<span> printf "%3d%% [", percent</span>
<span> for (i=0;i<=percent;i++)</span>
<span> printf "="</span>
<span> printf ">"</span>
<span> for (i=percent;i<100;i++)</span>
<span> printf " "</span>
<span> printf "]\r"</span>
<span> }</span>
<span> }</span>
<span> END { print "" }'</span> <span>total_size</span><span>=</span><span>$(</span>stat -c <span>'%s'</span> <span>"${1}"</span><span>)</span> <span>count</span><span>=</span>0
<span>}</span>
</pre></div><p>In action:</p><pre style="white-space: pre-wrap; word-wrap: break-word; ">% cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null
76% [===========================================> ]
</pre><br><a href="http://news.ycombinator.com/item?id=1166542" target="_blank" style="color: rgb(42, 93, 176); ">Comments</a></div><div><br></div></span></div>