<?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; shell</title>
	<atom:link href="http://happygiraffe.net/blog/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 10:40:06 +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>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>
	</channel>
</rss>

