<?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>Jabbering Giraffe &#187; tips</title>
	<atom:link href="http://happygiraffe.net/blog/tag/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 20:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>assignment alignment in vim</title>
		<link>http://happygiraffe.net/blog/2009/07/09/vim-assignment-alignment/</link>
		<comments>http://happygiraffe.net/blog/2009/07/09/vim-assignment-alignment/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 09:42:32 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1551</guid>
		<description><![CDATA[I&#8217;ve just been reading some articles about programming vim from Damian Conway. * Scripting the Vim editor, Part 1: Variables, values, and expressions * Scripting the Vim editor, Part 2: User-defined functions The latter has a very useful example. function &#8230; <a href="http://happygiraffe.net/blog/2009/07/09/vim-assignment-alignment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just been reading some articles about programming vim from <a href="http://en.wikipedia.org/wiki/Damian_Conway">Damian Conway</a>.</p>
<p>* <a href="http://www.ibm.com/developerworks/linux/library/l-vim-script-1/index.html">Scripting the Vim editor, Part 1: Variables, values, and expressions</a><br />
* <a href="http://www.ibm.com/developerworks/linux/library/l-vim-script-2/index.html">Scripting the Vim editor, Part 2: User-defined functions</a></p>
<p>The latter has a <em>very</em> useful example.</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">function</span> AlignAssignments<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #C5A22D;">&quot; Patterns needed to locate assignment operators. &quot;</span>
   <span style="color: #804040;">let</span> ASSIGN_OP   = <span style="color: #C5A22D;">'[-+*/%|&amp;]<span style="">\?</span>=<span style="">\@</span>&lt;!=[=~]<span style="">\@</span>!'</span>
   <span style="color: #804040;">let</span> ASSIGN_LINE = <span style="color: #C5A22D;">'^<span style="">\(</span>.<span style="">\{</span>-}<span style="">\)</span><span style="">\s</span>*<span style="">\(</span>'</span> <span style="color: #000000;">.</span> ASSIGN_OP <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'<span style="">\)</span>'</span>
&nbsp;
   <span style="color: #C5A22D;">&quot; Locate block of code to be considered (same indentation, no blanks) &quot;</span>
   <span style="color: #804040;">let</span> indent_pat = <span style="color: #C5A22D;">'^'</span> <span style="color: #000000;">.</span> <span style="color: #25BB4D;">matchstr</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">getline</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span>, <span style="color: #C5A22D;">'^<span style="">\s</span>*'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'<span style="">\S</span>'</span>
   <span style="color: #804040;">let</span> firstline  = <span style="color: #25BB4D;">search</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'^<span style="">\%</span>('</span> <span style="color: #000000;">.</span> indent_pat <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'<span style="">\)</span><span style="">\@</span>!'</span>, <span style="color: #C5A22D;">'bnW'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #000000; font-weight:bold;">1</span>
   <span style="color: #804040;">let</span> lastline   = <span style="color: #25BB4D;">search</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'^<span style="">\%</span>('</span> <span style="color: #000000;">.</span> indent_pat <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'<span style="">\)</span><span style="">\@</span>!'</span>,  <span style="color: #C5A22D;">'nW'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">-</span> <span style="color: #000000; font-weight:bold;">1</span>
   <span style="color: #804040;">if</span> lastline <span style="color: #000000;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span>
       <span style="color: #804040;">let</span> lastline = <span style="color: #25BB4D;">line</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'$'</span><span style="color: #000000;">&#41;</span>
   <span style="color: #804040;">endif</span>
&nbsp;
   <span style="color: #C5A22D;">&quot; Find the column at which the operators should be aligned. &quot;</span>
   <span style="color: #804040;">let</span> max_align_col = <span style="color: #000000; font-weight:bold;">0</span>
   <span style="color: #804040;">let</span> max_op_width  = <span style="color: #000000; font-weight:bold;">0</span>
   <span style="color: #804040;">for</span> linetext <span style="color: #804040;">in</span> <span style="color: #25BB4D;">getline</span><span style="color: #000000;">&#40;</span>firstline, lastline<span style="color: #000000;">&#41;</span>
       <span style="color: #C5A22D;">&quot; Does this line have an assignment in it? &quot;</span>
       <span style="color: #804040;">let</span> left_width = <span style="color: #804040;">match</span><span style="color: #000000;">&#40;</span>linetext, <span style="color: #C5A22D;">'<span style="">\s</span>*'</span> <span style="color: #000000;">.</span> ASSIGN_OP<span style="color: #000000;">&#41;</span>
       <span style="color: #804040;">if</span> left_width <span style="color: #000000;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span>
           <span style="color: #804040;">let</span> max_align_col = <span style="color: #25BB4D;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>max_align_col, left_width<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
           <span style="color: #804040;">let</span> op_width      = <span style="color: #25BB4D;">strlen</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">matchstr</span><span style="color: #000000;">&#40;</span>linetext, ASSIGN_OP<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
           <span style="color: #804040;">let</span> max_op_width  = <span style="color: #25BB4D;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>max_op_width, op_width <span style="color: #000000;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
       <span style="color: #804040;">endif</span>
   <span style="color: #804040;">endfor</span>
&nbsp;
   <span style="color: #C5A22D;">&quot; Code needed to reformat lines so as to align operators. &quot;</span>
   <span style="color: #804040;">let</span> FORMATTER = <span style="color: #C5A22D;">'<span style="">\=</span>printf(&quot;%-*s%*s&quot;, max_align_col, submatch(1),
   <span style="">\ </span>                                   max_op_width,  submatch(2))'</span>
&nbsp;
   <span style="color: #C5A22D;">&quot; Reformat lines with operators aligned in the appropriate column. &quot;</span>
   <span style="color: #804040;">for</span> linenum <span style="color: #804040;">in</span> <span style="color: #25BB4D;">range</span><span style="color: #000000;">&#40;</span>firstline, lastline<span style="color: #000000;">&#41;</span>
       <span style="color: #804040;">let</span> oldline = <span style="color: #25BB4D;">getline</span><span style="color: #000000;">&#40;</span>linenum<span style="color: #000000;">&#41;</span>
       <span style="color: #804040;">let</span> newline = <span style="color: #25BB4D;">substitute</span><span style="color: #000000;">&#40;</span>oldline, ASSIGN_LINE, FORMATTER, <span style="color: #C5A22D;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
       <span style="color: #804040;">call</span> <span style="color: #25BB4D;">setline</span><span style="color: #000000;">&#40;</span>linenum, newline<span style="color: #000000;">&#41;</span>
   <span style="color: #804040;">endfor</span>
endfunction
&nbsp;
nmap <span style="color: #668080;">&lt;silent&gt;</span> ;= <span style="color: #000000;">:</span><span style="color: #804040;">call</span> AlignAssignments<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #668080;">&lt;cr&gt;</span></pre></div></div>

<p>This allows you to line up assignments so that all the the equals appear in a column.  I find this much easier to read.</p>
<p>To use this code, paste it into a file <code>~/.vim/plugin/AlignAssignments.vim</code>.  It&#8217;ll get loaded automatically.  From then on you use it by going to a group of assignments and hitting <code>;=</code>.  Blam!</p>
<p>There are <a href="http://www.vim.org/scripts/script_search_results.php?keywords=align&#038;script_type=&#038;order_by=rating&#038;direction=descending&#038;search=search">other alignment plugins</a> available in the <a href="http://www.vim.org/scripts/">vim scripts archive</a>, but this one is relatively small &#038; simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/07/09/vim-assignment-alignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>find(1) abuse</title>
		<link>http://happygiraffe.net/blog/2009/06/12/find1-abuse/</link>
		<comments>http://happygiraffe.net/blog/2009/06/12/find1-abuse/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 22:07:11 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1539</guid>
		<description><![CDATA[A colleague wanted to find all the files that end up *.disp or *.frag. Easy enough, right? In the shell you can say *.{disp,frag}. $ ls *.&#123;disp,frag&#125; foo.disp foo.frag Except that this doesn&#8217;t work with find: $ find . -name &#8230; <a href="http://happygiraffe.net/blog/2009/06/12/find1-abuse/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A colleague wanted to find all the files that end up <code>*.disp</code> or <code>*.frag</code>.  Easy enough, right?  In the shell you can say <code>*.{disp,frag}</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#123;</span>disp,frag<span style="color: #7a0874; font-weight: bold;">&#125;</span>
foo.disp
foo.frag</pre></div></div>

<p>Except that this doesn&#8217;t work with find:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.{disp,frag}'</span></pre></div></div>

<p>Why not?  Because <a href="http://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html#Brace-Expansion">braces</a> aren&#8217;t <a href="http://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html#Filename-Expansion">globs</a>, so they&#8217;re not supported by <a href="http://www.gnu.org/software/findutils/">find(1)</a>.</p>
<p>What can you do instead?</p>
<p>Firstly, you can use the <a href="http://www.gnu.org/software/findutils/manual/html_mono/find.html#Full-Name-Patterns"><code>-regex</code></a> flag.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-regex</span> <span style="color: #ff0000;">'.*\.\(disp\|frag\)'</span>
.<span style="color: #000000; font-weight: bold;">/</span>foo.disp
.<span style="color: #000000; font-weight: bold;">/</span>foo.frag</pre></div></div>

<p>This is particularly awful because find defaults to the <a href="http://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-of-Regexps.html#Syntax-of-Regexps">emacs style of regexes</a> (which took me ages to remember the details of) and means you end up with <a href="http://en.wikipedia.org/wiki/Leaning_toothpick_syndrome">leaning toothpick syndrome</a>.  And you&#8217;re matching the whole filename, not a subset, so you have to have the <code>.*</code> on the front.</p>
<p>The second option is to use find&#8217;s expression language.  Find <em>THIS FILE</em> or <em>THAT FILE</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">find</span> . \<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.disp'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.frag'</span> \<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-print</span>
.<span style="color: #000000; font-weight: bold;">/</span>foo.disp
.<span style="color: #000000; font-weight: bold;">/</span>foo.frag</pre></div></div>

<p>This is a bit more readable, but you have to remember that the parentheses are quoted because the shell likes to munch on them.  Overall, it does seem preferable to <code>-regex</code> though.</p>
<p>Like all these things, you can <a href="http://www.chiark.greenend.org.uk/~pmaydell/find/">take it too far</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/12/find1-abuse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Byte Order Marks</title>
		<link>http://happygiraffe.net/blog/2009/02/19/removing-byte-order-marks/</link>
		<comments>http://happygiraffe.net/blog/2009/02/19/removing-byte-order-marks/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 11:10:35 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1476</guid>
		<description><![CDATA[I keep getting sent files, which are encoded in UTF-8, but include a BOM. Which is completely unnecessary. Thankfully, it&#8217;s pretty easy to remove with vim. Just load up the file and type in :set nobomb (docs for the bomb &#8230; <a href="http://happygiraffe.net/blog/2009/02/19/removing-byte-order-marks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I keep getting sent files, which are encoded in UTF-8, but include a <abbr title="Byte order mark"><a href="http://en.wikipedia.org/wiki/Byte-order_mark">BOM</a></abbr>.  Which is completely unnecessary.  Thankfully, it&#8217;s pretty easy to remove with <a href="http://www.vim.org/">vim</a>.  Just load up the file and type in <code>:set nobomb</code> (<a href="http://www.vim.org/htmldoc/options.html#'bomb'">docs for the bomb option</a>) and save.  Problem successfully defused!</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/02/19/removing-byte-order-marks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim completion</title>
		<link>http://happygiraffe.net/blog/2008/10/30/vim-completion/</link>
		<comments>http://happygiraffe.net/blog/2008/10/30/vim-completion/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 14:54:10 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1404</guid>
		<description><![CDATA[I&#8217;ve just found something rather useful in vim: :set wildmode. Normally in vim, you can use TAB to complete filenames. So you enter :e some/ve&#60;TAB&#62; and vim pads it out to :e some/very_long_filename.html. Lovely. But in a directory full of &#8230; <a href="http://happygiraffe.net/blog/2008/10/30/vim-completion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just found something rather useful in <a href="http://www.vim.org/">vim</a>:  <a href="http://www.vim.org/htmldoc/options.html#%27wildmode%27">:set wildmode</a>.  Normally in vim, you can use TAB to complete filenames.  So you enter <code>:e some/ve&lt;TAB&gt;</code> and vim pads it out to <code>:e some/very_long_filename.html</code>.  Lovely.</p>
<p>But in a directory full of files with similar prefixes, it&#8217;s less than helpful.  I hit <code>:e acc&lt;TAB&gt;</code> and vim expands to <code>:e acc_click_here_to_continue.html</code>.  But then I need to backspace all the way back so it reads <code>:e acc</code> and hit TAB again.  This is a pain.</p>
<p>But, if you stick <code>set wildmode=longest,full</code> into <code>~/.vimrc</code>, then vim stops when it&#8217;s completed the longest unique prefix (&#8220;acc&#8221;) and gives you a chance to type.  Or, if you just keep banging on the TAB key like a deranged gibbon it will start rotating through all the possible completions.  But by stopping at that point, I get a chance to intervene.</p>
<p>It sounds like a teeny-tiny little thing.  But it&#8217;s one less thing that&#8217;s getting in the way of me doing things.</p>
<p>That said, any time saved has already been wiped out by writing this blog entry.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/30/vim-completion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Curl Tip</title>
		<link>http://happygiraffe.net/blog/2008/09/04/curl-tip/</link>
		<comments>http://happygiraffe.net/blog/2008/09/04/curl-tip/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 16:15:48 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1363</guid>
		<description><![CDATA[Sometimes when running curl, you need to disable the Pragma: no-cache header it sends by default. It turns out that this is quite easy to do: % curl -v -H Pragma: http://example.com/]]></description>
			<content:encoded><![CDATA[<p>Sometimes when running <a href="http://curl.haxx.se/">curl</a>, you need to disable the <code>Pragma: no-cache</code> header it sends by default.  It turns out that this is quite easy to do:</p>
<pre>
  % curl -v -H Pragma: http://example.com/
</pre>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/09/04/curl-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Sysadmin Toolbox</title>
		<link>http://happygiraffe.net/blog/2006/04/17/my-sysadmin-toolbox/</link>
		<comments>http://happygiraffe.net/blog/2006/04/17/my-sysadmin-toolbox/#comments</comments>
		<pubDate>Mon, 17 Apr 2006 10:32:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[multitail]]></category>
		<category><![CDATA[mutt]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[strace]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[wiki]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/04/17/my-sysadmin-toolbox/</guid>
		<description><![CDATA[After seeing lots of these at Linux.com recently, I thought I&#8217;d try to come up with my own list. I used to be a sysadmin (I&#8217;m now a programmer), and I&#8217;ve long felt that you really a good set of &#8230; <a href="http://happygiraffe.net/blog/2006/04/17/my-sysadmin-toolbox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After seeing lots of these at <a href="http://www.linux.com/">Linux.com</a> recently, I thought I&#8217;d try to come up with my own list.  I used to be a sysadmin (I&#8217;m now a programmer), and I&#8217;ve long felt that you really a good set of tools (and to know how to use them) in order to be most productive.</p>
<ul>
<li>
<p><a href="http://www.zsh.org/">zsh</a></p>
<p>I spend the vast majority of my time at a command line.  Zsh ensures I make best use of my time.  If you&#8217;ve used bash, you might think you know what completion is&#8212;press the tab key and it fills out file names for you.  But zsh takes it to a whole new level.  Not only does it complete file names, but also users, hostnames, option flags, environment variables, PIDs and more.  On top of that, it does it in a context-sensitive manner.  So if you type in &#8220;chown &#8221; and press <span class="caps">TAB</span>, it starts completing usernames.  Type in a space and another <span class="caps">TAB</span> and it starts completing file names again.</p>
<p>On top of that, it allows <em>partial</em> completion.  If I type in <code>/u/l/e/r/</code> and press <span class="caps">TAB</span>, It gets expanded to <code>/usr/local/etc/rc.d/</code>.  This is phenomenally useful.</p>
<p>But it&#8217;s not just completion that zsh is good at.  It&#8217;s also good at <em>globbing</em>.  That&#8217;s turning wildcards into filenames.  In addition to the usual forms of globbing, zsh can glob recursively.  So if I want to look for &#8220;foobar&#8221; in all my files (but not directories), I can do:</p>
<pre>
  % grep foobar **/*(.)
</pre>
<p>The &#8220;<code>**/*</code>&#8221; is the recursive glob, and the &#8220;<code>(.)</code>&#8221; limits it to files and not directories.  You can also limit by user, by timestamp and a few other things.</p>
<p>This is just covering the surface of zsh.  Suffice to say that if you make heavy use of the command line, investing some time in learning zsh will make you vastly more productive.</p>
</li>
<li>
<p><a href="http://www.gnu.org/software/screen/">screen</a></p>
<p>This was mentioned on a few of the other lists as well.  <span class="caps">GNU</span> Screen on the face of it doesn&#8217;t do anything.  You just end up with another command line when you first run it.  But the beauty of it is that if you get disconnected, you can just log back in, run <code>screen -d -r</code> and pick up exactly where you left off.  For me, this is ideal, given the flakiness of my home wireless network.  But you might want to use it so you can shut down your PC at night and pick up where you left off in the morning.</p>
<p>On top of that, screen lets you run multiple command lines at once inside it, log the output and cut&#8217;n&#8217;paste between them.  Think of it as a safety harness for your work.</p>
</li>
<li>
<p><a href="http://samba.anu.edu.au/rsync/">rsync</a></p>
<p>Rsync is one of the closer things to magic that&#8217;s around.  It&#8217;s a simple file copying utility.  But the clever bit is that it only copies the things that have changed.  This doesn&#8217;t sound like much until you&#8217;ve edited several files in a collection which is 200Mb and needs to be on another box.  When rsync tells you it&#8217;s finished and only transferred 10Kb instead of 200Mb, you&#8217;ll really come to appreciate it.</p>
<p>If you&#8217;re still using tar/gzip or zip to create an archive to ship to another computer, stop wasting your time and disk space.  Learn to use rsync and your life will be far more pleasant.</p>
</li>
<li>
<p><a href="http://www.openssh.com/">OpenSSH</a></p>
<p>Thankfully, ssh is pretty ubiquitous these days.  It seems to have mostly worked in its mission to eliminate <a href="http://en.wikipedia.org/wiki/Telnet">telnet</a>.  But it has a few tricks that are worth knowing about.</p>
<p>First, the agent.  One of the nice things about ssh is that it doesn&#8217;t have to rely on sending passwords around.  Instead, you can use public key authentication.  However, even typing in your passphrase can get pretty tedious after a while for every connection.  Enter the ssh-agent.  Just stick <code>eval `ssh-agent`</code> in your startup scripts and then run <code>ssh-add</code> once.  After that, you don&#8217;t get asked for your passphrase any more.  The only caveat is that now you <em>really</em> need to lock your screen when you walk away from it.</p>
<p>Next are the tunnels.  Ssh is able to create network &#8220;tunnels&#8221; in and out of otherwise secure locations.  This is very handy for creating ad-hoc networks.  For example, I&#8217;m allowed to ssh into my work, but not to anything else.  Yet, I can use <a href="http://en.wikipedia.org/wiki/Remote_Desktop_Protocol"><span class="caps">RDP</span></a> to connect to my workstation by running this command:</p>
<pre>
  % ssh -L3389:myworkstation:3389 firewall.mywork.com
  % rdesktop localhost
</pre>
<p>That says: listen on port 3389, and any connections that come in, forward them on to myworkstation port 3389 from the other side of the ssh connection to firewall.mywork.com.</p>
<p>If you&#8217;re on windows, check out <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a>.  It&#8217;s got all the features, but wrapped up in a nice <span class="caps">GUI</span> interface.</p>
</li>
<li>
<p><a href="http://people.freebsd.org/~abe/">lsof</a> / <a href="http://docs.sun.com/app/docs/doc/816-5165/6mbb0m9o6?a=view">pfiles</a> / <a href="http://www.freebsd.org/cgi/man.cgi?query=sockstat&#38;sektion=1">sockstat</a></p>
<p>Lsof (List Open Files) is one of the first diagnostic tools that I reach for when I need to understand something.  The purpose is simple: it tells you what files (and network connections) a process has open.  If you&#8217;re wondering where a process is logging to, this might be able to tell you.  Conversely, it can also tell you which processes have a particular file open (usually a lock file).</p>
<p>On Solaris, the pfiles command is similiar.</p>
<p>On a related note, FreeBSD also has the very, very useful sockstat command, which lists all open sockets and what processes hold them open.  The useful bit is that it does this without needing to be root (unlike Linux&#8217;s <code>netstat -anp</code>).</p>
</li>
<li>
<p><a href="http://www.liacs.nl/~wichert/strace/">strace</a> / <a href="http://docs.sun.com/app/docs/doc/816-5165/6mbb0m9ut?a=view">truss</a> / <a href="http://www.freebsd.org/cgi/man.cgi?query=ktrace&#38;sektion=1">ktrace</a></p>
<p>These are the second diagnostic tool that I reach for when something&#8217;s not right.  Unix operating systems have a very clear distinction between userland and kernel, and this tool shows all the points where a program crosses between the two (makes a system call).  If you really want to know how a program is interacting with its environment, these tools will tell you.  It&#8217;s godo for answering questions like:</p>
<ul>
<li>What files is this process opening and closing?</li>
<li>What connections to the network are being made?</li>
<li>What&#8217;s been read in by this program?</li>
</ul>
</li>
<li>
<p><a href="http://www.vanheusden.com/multitail/">multitail</a></p>
<p>A recent addition to my toolbox.  It&#8217;s like <code>tail -f</code>, except that it looks at more than one file at once.  It also does highlighting of search terms.  Dead handy.</p>
</li>
<li>
<p><a href="http://curl.haxx.se/">curl</a></p>
<p>Most of the stuff I do these days involves the web.  Curl is a fantastic little tool for inspecting the web from the command line.  It covers all the protocols you need, and can dump out any information about the transaction.  Want to issue a <span class="caps">PUT</span> request to an <span class="caps">SSL</span> server, verifying the certificate and specifing basic auth?  It&#8217;s got you covered.</p>
</li>
<li>
<p><a href="http://www.vim.org/">vim</a></p>
<p>Everybody needs a good editor.  Vim isn&#8217;t the only choice, but it&#8217;s pretty likely to be available wherever you go.  And once you&#8217;ve started learning how to use it properly, you won&#8217;t go back.  In particular, I can&#8217;t live without <code>^P</code> and <code>^N</code> for doing completion inside the file you&#8217;re editing.</p>
</li>
<li>
<p><a href="http://www.courtesan.com/sudo">sudo</a></p>
<p>If you&#8217;re still using <a href="http://www.freebsd.org/cgi/man.cgi?query=su&#38;sektion=1" title="1">su</a>, then you need help.  Sudo allows you to dole out root access on a much more granular level and you get proper logging of who did what.  If you haven&#8217;t looked at the manual recently, then check out <code>sudo -e</code> for editing a file as another user.  It ensures that you get your regular editor (vim or Emacs) instead of the incredibly unhelpful <a href="http://www.freebsd.org/cgi/man.cgi?query=ed&#38;sektion=1" title="1">ed</a> that root probably defaults to.</p>
</li>
<li>
<p><a href="http://subversion.tigris.org/">subversion</a></p>
<p>Everybody needs version control.  If you&#8217;re editing files, stick them in subversion.  You won&#8217;t regret it.  Particularly when you need to see what those files looked like 6 months ago.</p>
</li>
<li>
<p><a href="http://www.mutt.org/">mutt</a></p>
<p>Every now and again, you need to deal with mailbox files.  Mutt is a great choice for that, thanks to its mini language for filtering mail.  Need delete all mail over 10 days old sent by cron@somehost?  Not a problem.  Even if you don&#8217;t use it on a regular basis, it&#8217;s worth getting familiar with.</p>
</li>
<li>
<p><a href="http://www.gnu.org/software/gdb/">gdb</a></p>
<p>Yes, this is a programmers tool.  But it&#8217;s worth knowing a tiny amount about if you&#8217;re a sysadmin as well.  What for?  It lets you see <em>why</em> something dumped core.  If you find a core file, then do <code>file core</code> to see what program left it behind and then <code>gdb /path/to/program core</code>.  When you&#8217;re inside gdb, type in <code>where</code> and it will (most of the time) give you a stack trace, showing what it was doing at the time of the crash.  This is normally a big help in trying to figure out what went wrong.</p>
<p>You can also use gdb to find out what a running program is doing by specifing a <span class="caps">PID</span> instead of a corefile.</p>
</li>
<li>
<p><a href="http://www.perl.org/">perl</a> / <a href="http://www.python.org/">python</a> / <a href="http://www.ruby-lang.org/">ruby</a></p>
<p>If you perform the same series of actions more than a couple of times, you should consider investing some time in automating the process.  Shell scripts are handy, but can only go so far.  Learning one of these languages will give you a really powerful ability to write your own sysadmin toolbox.</p>
</li>
<li>
<p><a href="http://www.mediawiki.org/wiki/MediaWiki">mediawiki</a></p>
<p>Documentation.  Everybody hates doing it.  Why not make it as easy as possible?  A wiki is the answer to that, and mediawiki is one of the better pieces of wiki software out there.  It&#8217;s pretty simple to get going (although it does depend on MySQL).</p>
<p>Remember: getting it documented is first priority.  Once the information is in the wiki, it can be restructured later.  So long as the information is there, it will be searchable (and hence useful).</p>
</li>
</ul>
<p>Hmmm, that&#8217;s a bit more than the 10 they wanted.  But it&#8217;s a large portion of my regular toolkit.  Hopefully there&#8217;s something useful for other people in there as well&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/04/17/my-sysadmin-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MultiTail</title>
		<link>http://happygiraffe.net/blog/2006/03/28/multitail/</link>
		<comments>http://happygiraffe.net/blog/2006/03/28/multitail/#comments</comments>
		<pubDate>Tue, 28 Mar 2006 12:24:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/03/28/multitail/</guid>
		<description><![CDATA[I used to use tail -f a lot to follow the end of a logfile, as it was written to. Nowadays I tend to use less +F instead, as it can highlight search terms for you as well. But I&#8217;ve &#8230; <a href="http://happygiraffe.net/blog/2006/03/28/multitail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I used to use <code>tail -f</code> a lot to follow the end of a logfile, as it was written to.  Nowadays I tend to use <code>less +F</code> instead, as it can highlight search terms for you as well.</p>
<p>But I&#8217;ve just seen <a href="http://www.vanheusden.com/multitail/">multitail</a>.  It splits the screen and lets you follow as many log files as you like.  Very handy.  And it can nicely colorise the log entries if it recognises the format.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/03/28/multitail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reboots for Users</title>
		<link>http://happygiraffe.net/blog/2006/02/12/reboots-for-users/</link>
		<comments>http://happygiraffe.net/blog/2006/02/12/reboots-for-users/#comments</comments>
		<pubDate>Sun, 12 Feb 2006 10:30:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/02/12/reboots-for-users/</guid>
		<description><![CDATA[Jamis Buck has a good article on how to run TextDrive and Lighttpd together. It involves switching the Rails FastCGI processes to be managed independently from the web server. Essentially, the Rails FastCGI runners become independent daemons. But what&#8217;s really &#8230; <a href="http://happygiraffe.net/blog/2006/02/12/reboots-for-users/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Jamis Buck has a good article on how to run <a href="http://jamis.jamisbuck.org/articles/2006/02/11/tip-textdrive-and-lighttpd">TextDrive and Lighttpd</a> together.  It involves switching the Rails FastCGI processes to be managed independently from the web server.  Essentially, the Rails FastCGI runners become independent daemons.</p>
<p>But what&#8217;s really useful is the tip in the <a href="http://jamis.jamisbuck.org/articles/2006/02/11/tip-textdrive-and-lighttpd#comment-1332">first comment</a>.  It mentions an obscure crontab feature: <code>@reboot</code>.  This will let you, as a user, execute a script when the machine boots up.  This is dead handy, as it means that your application can be automatically restarted on server boot without having to bother the sysadmins.</p>
<p>More info:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Vixie_cron">Vixie cron</a></li>
<li><a href="http://jeremy.zawodny.com/blog/archives/001021.html">Vixie cron&#8217;s @reboot</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/02/12/reboots-for-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

