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; ">
&lt; zed0&gt; 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>&quot;${1}&quot;</span> <span>&quot;${2}&quot;</span> 2&gt;&amp;1 <span>\</span>
      | awk <span>&#39;{</span>
<span>        count += $NF</span>
<span>            if (count % 10 == 0) {</span>
<span>               percent = count / total_size * 100</span>
<span>               printf &quot;%3d%% [&quot;, percent</span>
<span>               for (i=0;i&lt;=percent;i++)</span>
<span>                  printf &quot;=&quot;</span>
<span>               printf &quot;&gt;&quot;</span>
<span>               for (i=percent;i&lt;100;i++)</span>
<span>                  printf &quot; &quot;</span>
<span>               printf &quot;]\r&quot;</span>
<span>            }</span>
<span>         }</span>
<span>         END { print &quot;&quot; }&#39;</span> <span>total_size</span><span>=</span><span>$(</span>stat -c <span>&#39;%s&#39;</span> <span>&quot;${1}&quot;</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% [===========================================&gt;                    ]
</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>