<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Myrtle Street Labs &#187; bag o&#8217; tricks</title>
	<atom:link href="http://labs.myrtlestreet.org/category/bag-o-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.myrtlestreet.org</link>
	<description>experiments in technology and culture</description>
	<lastBuildDate>Mon, 12 Oct 2009 19:18:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel="next" href="http://labs.myrtlestreet.org/category/bag-o-tricks/feed/?page=2" />

		<item>
		<title>unix shell tricks: progress feedback for long running processes</title>
		<link>http://labs.myrtlestreet.org/2009/09/03/handy-unix-trick-progress-feedback-for-long-running-processes/</link>
		<comments>http://labs.myrtlestreet.org/2009/09/03/handy-unix-trick-progress-feedback-for-long-running-processes/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 20:49:27 +0000</pubDate>
		<dc:creator>sstave</dc:creator>
				<category><![CDATA[bag o' tricks]]></category>
		<category><![CDATA[*nix]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://labs.myrtlestreet.org/?p=725</guid>
		<description><![CDATA[Frequently I need to execute a fairly long running task, such as unpacking a large tar file or running a long build.  I want to get feedback on the progress of the task, but I don&#8217;t necessarily want to fill my terminal window with lots of superfluous text by using the verbose output option.  Not [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_735" class="wp-caption alignright" style="width: 230px"><a href="http://en.wikipedia.org/wiki/File:Ambrogio_Lorenzetti_002-detail-Temperance.jpg"><img class="size-medium wp-image-735" title="Ambrogio_Lorenzetti_002-detail-Temperance" src="http://labs.myrtlestreet.org/wp-content/uploads/2009/09/Ambrogio_Lorenzetti_002-detail-Temperance-220x300.jpg" alt="Temperance bearing an hourglass; detail of Lorenzetti's Allegory of Good Government, 1338" width="220" height="300" /></a><p class="wp-caption-text">Temperance bearing an hourglass; detail of Lorenzetti&#39;s Allegory of Good Government, 1338</p></div>
<p>Frequently I need to execute a fairly long running task, such as unpacking a large tar file or running a long build.  I want to get feedback on the progress of the task, but I don&#8217;t necessarily want to fill my terminal window with lots of superfluous text by using the verbose output option.  Not only is the scrolling text distracting and difficult to follow, outputting the text can be  a significant bottleneck on slow connections.</p>
<p>To solve this problem I use a script called &#8220;dots,&#8221; which I list below.  This script prints a single period character for every 1000 lines of input.  You can specify a different number of lines necessary to create a dot as the first argument to the command.  Any command with verbose output can be piped into dots to generate a simple progress bar.</p>
<hr />
<pre>#!/usr/bin/perl

$| = 1;  # flush output immediately
$i = 0;

if ($#ARGV &lt; 0) {
  $number = 1000;
} else {
  $number = shift(@ARGV);
}

while (&lt;STDIN&gt;) {
  print '.' unless ($i % $number);
  $i++;
}

print "\n";</pre>
<hr />Some examples:</p>
<pre>jdblair@zaphod:~/src$ tar xvfj linux-2.6.30.5.tar.bz2 | dots
..............................</pre>
<pre>jdblair@zaphod:~/src$ rm -rfv linux-2.6.30.5 | dots
..............................</pre>
<p>If you still want to be able to check the output, such as the text generated by a long running make command, use the tee command to generate a log file.  This example generates a dot for every 10 lines of output, since the compiler output is generated comparatively slowly.</p>
<pre>jdblair@zaphod:~/src/linux-2.6.30.5$ make bzImage 2&gt;&amp;1 | tee build.log | dots 10
<pre>................................................................................
................................................................................
....................</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://labs.myrtlestreet.org/2009/09/03/handy-unix-trick-progress-feedback-for-long-running-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unix shell tricks: one way to avoid deleting important files by accident</title>
		<link>http://labs.myrtlestreet.org/2009/09/02/unix-shell-tricks-one-way-to-avoid-deleting-important-files-by-accident/</link>
		<comments>http://labs.myrtlestreet.org/2009/09/02/unix-shell-tricks-one-way-to-avoid-deleting-important-files-by-accident/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 17:19:25 +0000</pubDate>
		<dc:creator>sstave</dc:creator>
				<category><![CDATA[bag o' tricks]]></category>
		<category><![CDATA[*nix]]></category>
		<category><![CDATA[accidents]]></category>
		<category><![CDATA[friends]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://labs.myrtlestreet.org/?p=704</guid>
		<description><![CDATA[ ]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-705 alignright" title="asterisk" src="http://labs.myrtlestreet.org/wp-content/uploads/2009/09/asterisk.jpg" alt="asterisk" width="284" height="284" />When I was in college I once had several files in my home directory with semicolons in the middle of their names.  I decided to remove them all at once with this command:</p>
<pre>$ rm *;*</pre>
<p>The response from the shell was this:</p>
<pre>sh: *: command not found</pre>
<p>Then, to my horror, when I listed the directory I could see all my files were gone.</p>
<p>The unix nerds in the audience will have already noticed what happened.  You see, the semicolon is the magic character that ends a command line.  I had told the shell to remove all my files then run a command called *.</p>
<p>Game over, at least for all the files in my home directory.</p>
<p>This story came up in a particularly geeky thread yesterday on Facebook, and Nick Shapiro told me a trick he learned from our mutual friend <a href="http://www.zer0.org/~gsutter/">Greg Sutter</a>.</p>
<p>Put a file called &#8220;-i&#8221; in directories containing vital files.  If you run &#8220;rm *&#8221; the file called &#8220;-i&#8221; tricks rm into running in &#8220;interactive&#8221; mode, which gives you a chance to bail out.</p>
<p>Here&#8217;s an example:</p>
<pre>$ mkdir tmp; cd tmp
$ touch ./-i
$ touch foo bar baz
$ rm *
rm: remove regular empty file `bar'?</pre>
<p>Now you have a chance to notice what happened and hit control-c to exit.</p>
<p>To remove the file, use</p>
<pre>$ rm ./-i</pre>
<p>Another handy related trick: a perl one-liner is also a great way to remove files with tricky names:</p>
<pre>$ perl -e "unlink('-i');"</pre>
<p>This trick also works great for files with other inconvenient names, like -, &#8211;, ;, &gt;, and &lt;, for which the &#8220;./&#8221; technique above doesn&#8217;t work.</p>
<p><strong>UPDATE:</strong></p>
<p>My friend Joe Ardent points out something I had forgotten: The GNU convention is to ignore any arguments after &#8220;&#8211;&#8221; in the argument list.  Thus, you can also do this:</p>
<pre>$ touch -- -i
$ rm -- -i</pre>
<p>Joe also reminds me that you can escape special shell characters using the backslash character.  Thus, &#8220;rm \&lt;&#8221; works, which is simpler than the perl one liner.  Just when you think you&#8217;re an expert in something&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.myrtlestreet.org/2009/09/02/unix-shell-tricks-one-way-to-avoid-deleting-important-files-by-accident/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>baking soda + super glue = instant plastic patch</title>
		<link>http://labs.myrtlestreet.org/2009/08/11/baking-soda-super-glue-instant-plastic-patch/</link>
		<comments>http://labs.myrtlestreet.org/2009/08/11/baking-soda-super-glue-instant-plastic-patch/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 14:00:15 +0000</pubDate>
		<dc:creator>John Blair</dc:creator>
				<category><![CDATA[bag o' tricks]]></category>
		<category><![CDATA[friends]]></category>
		<category><![CDATA[plastic]]></category>

		<guid isPermaLink="false">http://labs.myrtlestreet.org/?p=12</guid>
		<description><![CDATA[Use super glue and baking soda to make a tough patch for plastic.]]></description>
			<content:encoded><![CDATA[<p>Mixing baking soda and super glue makes an instant, strong, rock-hard patch for hard plastic. It can be used to fill in holes or build up missing material.  The resulting material is snow white and can be sanded.</p>
<p>Here&#8217;s what you do:</p>
<ol>
<li>If necessary, make a small form in the shape you want the patch to take.</li>
<li>Fill the form, or hole you are filling, with baking soda.</li>
<li>Dribble super glue into the baking soda until the powder is saturated.  It will foam up a little.  Do not be alarmed.  This is a feature.</li>
<li>Remove the form.  This may require some sanding since it will now be attached by super glue.</li>
<li>Sand rough edges to taste.</li>
</ol>
<p>I learned this trick from my friend <a href="http://www.brawer.com/gary.html">Gary Brawer</a>, who refers to the material as &#8220;amalgamated compound.&#8221; He explained that the name gives the otherwise banal sounding material more cred.</p>
<p>I watched Gary use &#8220;amalgamated compound&#8221; to repair a broken nut on a guitar (this is the plastic part at the top of the fret board that holds the strings in their proper position) and was totally amazed by the speed and the quality of the result.</p>
<p>Gary runs <a href="http://www.brawerguitarrepair.blogspot.com/">Gary Brawer Guitar and Bass Repair</a>.  I can&#8217;t recommend him strongly enough if you have a guitar in need of some TLC.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.myrtlestreet.org/2009/08/11/baking-soda-super-glue-instant-plastic-patch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>an annoying unix thing, and a workaround</title>
		<link>http://labs.myrtlestreet.org/2009/07/31/an-annoying-unix-thing-and-a-workaround/</link>
		<comments>http://labs.myrtlestreet.org/2009/07/31/an-annoying-unix-thing-and-a-workaround/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 14:17:30 +0000</pubDate>
		<dc:creator>John Blair</dc:creator>
				<category><![CDATA[bag o' tricks]]></category>
		<category><![CDATA[*nix]]></category>
		<category><![CDATA[friends]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://labs.myrtlestreet.org/?p=5</guid>
		<description><![CDATA[It is mildly irritating that ctrl-w means "paste" in emacs, but it means "close window" in virtually any other application, or in Firefox, "close tab."]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.myrtlestreet.org/wp-content/uploads/2009/07/heckert_gnu.small.png"><img class="alignleft size-full wp-image-279" style="margin-left: 10px; margin-right: 10px;" title="heckert_gnu.small" src="http://labs.myrtlestreet.org/wp-content/uploads/2009/07/heckert_gnu.small.png" alt="heckert_gnu.small" width="145" height="140" /></a></p>
<p>It is mildly irritating that ctrl-w means &#8220;paste&#8221; in emacs, but it means &#8220;close window&#8221; in virtually any other application, or in Firefox, &#8220;close tab.&#8221;  If I&#8217;m editing text in firefox (say, a wiki page or a blog post) I have tendency to type &#8220;ctrl-w&#8221; to paste text.</p>
<p>Bam, the tab closes, along with all my edits.</p>
<p>Luckily my friend Bill Richardson taught me to type &#8220;shift-ctrl-t.&#8221;  In Firefox this puts the tab you just had open back, along with all the text in the fields just as you had left them.</p>
<p>Thank you Bill!</p>
<p>If you didn&#8217;t have any other tabs open, or you&#8217;re using another app (like, say, evolution) you&#8217;re out of luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.myrtlestreet.org/2009/07/31/an-annoying-unix-thing-and-a-workaround/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
