<?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>mitch&#039;s meanderings&#187; Linux</title>
	<atom:link href="http://mitchcontla.com/category/tech/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://mitchcontla.com</link>
	<description>life, technology, running; links, photos, and videos</description>
	<lastBuildDate>Tue, 18 Oct 2011 19:32:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Display recursive directory listing in Terminal</title>
		<link>http://mitchcontla.com/2011/03/08/display-recursive-directory-listing-in-terminal/</link>
		<comments>http://mitchcontla.com/2011/03/08/display-recursive-directory-listing-in-terminal/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 15:03:43 +0000</pubDate>
		<dc:creator>mitch</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://mitchcontla.com/?p=333</guid>
		<description><![CDATA[Use Tree with Mac OS X to display files and folders in a recursive structure with sub folders and files appearing under their parent directories.]]></description>
			<content:encoded><![CDATA[<p><a href="http://mitchcontla.com/blog/wp-content/uploads/2011/03/shell_tree.png"><img src="http://mitchcontla.com/blog/wp-content/uploads/2011/03/shell_tree.png" alt="" title="shell_tree" width="300" height="270" class="alignleft size-full wp-image-335" /></a>Selecting List view in <a href="http://en.wikipedia.org/wiki/Finder">Finder</a> displays files and folders in a recursive structure with sub folders and files appearing under their parent directories.</p>

<p>If you work in <a href="http://en.wikipedia.org/wiki/Apple_Terminal">Terminal</a> with any regularity, you know there are times when listing a directory structure in a manner similar to Finder&#8217;s List view would be handy, but there is no built in command to do so.</p>

<p>Before I switched to Mac OS X, I used Linux where I discovered a package called <a href="http://mama.indstate.edu/users/ice/tree/index.html">Tree</a>. The package consists of a single command that when passed a directory, displays a recursive tree-like listing of its content in <span class="caps">ASCII </span>form. The source for the package is freely available and can be downloaded and built in just a couple minutes.</p>

<h3>Building Tree for Mac OS X</h3>
The following steps assume:<br />
<ol>
	<li>Your using Mac OS X 10.6 Snow Leopard</li>
	<li>The latest <a href="http://developer.apple.com/technologies/xcode.html">Xcode Tools</a> from the Snow Leopard <span class="caps">DVD </span>or downloaded from <a href="http://developer.apple.com/devcenter/mac/index.action">Apple</a> are installed</li>
	<li>Your shell&#8217;s <span class="caps">PATH </span>variable includes <code>/usr/local</code> (if you don&#8217;t know why or how, see this Hivelogic <a href="http://hivelogic.com/articles/using_usr_local/">post</a>)</li>
	<li>You have experience running <span class="caps">UNIX </span>commands in Terminal</li>
</ol>

<p>Change to or create a directory where you can download and unpack the source. I keep a &#8216;Projects&#8217; folder to use for this kind of task.</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">cd ~/Projects/src/</pre></div></div>




<h4>Download  and unpack the source code</h4>
The links and versions are current at the time of this writing. See the program <a href="http://mama.indstate.edu/users/ice/tree/index.html">site</a> for up to date information.<br />&nbsp;<br />


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">curl -O ftp://mama.indstate.edu/linux/tree/tree-1.5.3.tgz
tar xzvf tree-1.5.3.tgz</pre></div></div>




<p>Now change to the source directory:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">cd tree-1.5.3/</pre></div></div>




<h4>Modify the Makefile for Mac OS X</h4>
The source ships with a file called &#8216;Makefile&#8217; that contains information used by the build process to compile Tree. By default, the source builds for the Linux OS and installs to <code>/usr</code>. Use your favorite text editor to change the file for Mac OS X.<br />&nbsp;<br />

<p>Find the line that reads:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">prefix = /usr</pre></div></div>



<p>&#8230; and change to:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">prefix = /usr/local</pre></div></div>




<p>Find and uncomment (remove the leading &#8216;#&#8217;) the <code>CFLAGS</code> and <code>XOBJS</code> lines in the Mac OS X section of the Makefile so it looks like this:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;"># Uncomment for OS X:
#CC=cc
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
#LDFLAGS=
XOBJS=strverscmp.o</pre></div></div>




<p><strong>Compile and install</strong></p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">make
sudo make install</pre></div></div>




<p>Assuming you did not receive any errors during the build process, you should be able to type the following and see a recursive listing of all the files and folders in the current directory:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">tree</pre></div></div>




<p>If you want to see directories only, try this:</p>


<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">tree -d</pre></div></div>




<p>That&#8217;s all there is.</p>]]></content:encoded>
			<wfw:commentRss>http://mitchcontla.com/2011/03/08/display-recursive-directory-listing-in-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nautilus Script: Edit Remote Files (SSH) with Vim</title>
		<link>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/</link>
		<comments>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 08:11:41 +0000</pubDate>
		<dc:creator>mitch</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[gvim]]></category>
		<category><![CDATA[nautilus]]></category>
		<category><![CDATA[nautilus-script]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://mitch.contlafamily.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/</guid>
		<description><![CDATA[My on again, off again love affair with KDE is currently off (but that&#8217;s another story). I&#8217;m once again enjoying the simplicity of Gnome, and the elegance of Nautilus. The ability to graphically browse remote servers via SSH is great, but I found out that trying to edit a remote file chokes Vim. Apparently the [...]]]></description>
			<content:encoded><![CDATA[<p>My on again, off again love affair with <a href="http://www.kde.org/" title="K Desktop Environment"><span class="caps">KDE</span></a> is currently off (but that&#8217;s another story). I&#8217;m once again enjoying the simplicity of <a href="http://www.gnome.org/" title="Gnome Desktop">Gnome</a>, and the elegance of <a href="http://www.gnome.org/projects/nautilus/" title="Nautilus file manager">Nautilus</a>.</p>

<p>The ability to graphically browse remote servers via <acronym title="secure shell">SSH</acronym> is great, but I found out that trying to edit a remote file chokes <a href="http://www.vim.org/" title="Vim editor">Vim</a>. Apparently the netrw module does not handle an <span class="caps">SSH </span><acronym title="Uniform Resource Identifier">URI</acronym>, but rather prefers <acronym title="secure copy">SCP</acronym>. So a quick nautilus-script to the rescue.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
&nbsp;
files = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> unescape<span style="color: black;">&#40;</span>uri<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\s</span>'</span>, r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\\</span> '</span>, <span style="color: #dc143c;">urllib</span>.<span style="color: black;">unquote</span><span style="color: black;">&#40;</span>uri<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">getenv</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;NAUTILUS_SCRIPT_SELECTED_URIS&quot;</span>, <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^file://'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
        files.<span style="color: black;">append</span><span style="color: black;">&#40;</span>unescape<span style="color: black;">&#40;</span><span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^file://'</span>, r<span style="color: #483d8b;">&quot;&quot;</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^ssh://'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
        files.<span style="color: black;">append</span><span style="color: black;">&#40;</span>unescape<span style="color: black;">&#40;</span><span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^ssh://([^/]+)(/[^/]+){2}/(.*)$'</span>, r<span style="color: #483d8b;">'scp://<span style="color: #000099; font-weight: bold;">\1</span>/<span style="color: #000099; font-weight: bold;">\3</span>'</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> files:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;gvim &quot;&quot;&quot;</span> + <span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>files<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>




<p>Still some work to do, but for now it&#8217;s simple and effective.</p>]]></content:encoded>
			<wfw:commentRss>http://mitchcontla.com/2007/09/06/nautilus-script-edit-remote-files-ssh-with-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: It&#8217;s the little things</title>
		<link>http://mitchcontla.com/2007/06/27/bash-its-the-little-things/</link>
		<comments>http://mitchcontla.com/2007/06/27/bash-its-the-little-things/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 19:47:50 +0000</pubDate>
		<dc:creator>mitch</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[hints]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://mitch.contlafamily.com/2007/06/27/bash-its-the-little-things/</guid>
		<description><![CDATA[The Bash shell always amazes me. I needed to create a Maildir using the typical Maildir/cur, Maildir/new, Maildir/tmp structure and stumbled on this: $ mkdir -m 0700 -p Maildir/{cur,new,tmp} The -m and -p options are no-brainers, but the {cur,new,tmp} was new to me. It was easy to figure out what was going to happen&#8230; one [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.gnu.org/software/bash/" title="Bash - GNU Project">Bash</a> shell always amazes me. I needed to create a <a href="http://en.wikipedia.org/wiki/Maildir" title="Wikipedia: Maildir">Maildir</a> using the typical <code>Maildir/cur</code>, <code>Maildir/new</code>, <code>Maildir/tmp</code> structure and stumbled on this:</p>



<pre class="example"><code>$ mkdir -m 0700 -p Maildir/{cur,new,tmp}</code></pre>



<p>The <code>-m</code> and <code>-p</code> options are no-brainers, but the <code>{cur,new,tmp}</code> was new to me. It was easy to figure out what was going to happen&#8230; one command to create the Maildir directory, and the three subdirectories, I was simply unfamiliar with the syntax. A quick look at the <a href="http://www.gnu.org/software/bash/" title="Bash - GNU Project">Bash</a> man page and I discovered <a href="http://www.gnu.org/software/bash/manual/bashref.html#SEC27" title="Bash Reference Manual: Brace Expansion">Brace Expansion</a>:</p>

<blockquote>Brace expansion is a mechanism by which arbitrary strings may be generated.</blockquote>

<p>A comma separated list between opening and closing braces is expanded by the shell including any preamble (in my case Maildir/) or postscript. Brace expansion can also generate ranges:</p>



<pre class="example"><code>$ echo {1..10}
1 2 3 4 5 6 7 8 9 10</code></pre>



<p>Cool, huh?</p>]]></content:encoded>
			<wfw:commentRss>http://mitchcontla.com/2007/06/27/bash-its-the-little-things/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

