title: Recursively rename files using find and sed
body: <p>I want to go through a bunch of directories and rename all files that end in _test.rb to end in _spec.rb instead. It's something I've never quite figured out how to do with bash so this time I thought I'd put some effort in to get it nailed. I've so far come up short though, my best effort is:</p>
  
  <pre><code>find spec -name "*_test.rb" -exec echo mv {} `echo {} | sed s/test/spec/` \;
  </code></pre>
  
  <p><em>NB: there's an extra echo after exec so that the command is printed instead of run while I'm testing it.</em> </p>
  
  <p>When I run it the output for each matched filename is:</p>
  
  <pre><code>mv original original
  </code></pre>
  
  <p>i.e. the substitution by sed has been lost. What's the trick?</p>