title: bash: get path from current directory given sub-directory name
body: <p>Trying to write a script to clean up environment files after a resource is deleted. The problem is all the script is given as input is the name of the resource (this cannot be changed) with zero identifying information beyond that. <strong>How can I find the path of the directory the resource is sitting in?</strong></p>
  
  <p>The directory is set up a bit like the following, although much more extensive. All of these are directories, not files. There can be as many as 40+ directories to search, but the desired one is generally not more than 2-3 directories deep.</p>
  
  <pre><code>foo
      aaa
         aaa_green
         aaa_blue
      bbb
      ccc
         ccc_green
  bar
      ddd
      eee
         eee_green
         eee_blue
      fff
         fff_green
         fff_blue
         fff_pink
  </code></pre>
  
  <p>I might be handed input like <code>aaa_green</code> or just <code>ddd</code>. </p>
  
  <p>As an example, given <code>eee_blue</code> as input, I need to know <code>eee_blue</code>'s path from the working directory so I can cd there and delete the directory. IE, I would expect to return <code>bar/eee/eee_blue/</code> or <code>bar/eee/</code>, either is acceptable.</p>
  
  <p>The "best" option I can see currently is to cd into the lowest level of each directory via multiple greps, get each's contents and look for a match, and when it does (eventually) match save that cd'ing as the path. This frankly sounds awful and inefficient.</p>
  
  <p>The only other alternative method I could think of was a straight recursive grep, but I tested it and at 8 minutes it still hadn't finished running.</p>
  
  <p>This script needs to run on <strong>both mac and linux</strong>, although in a desperate pinch I could go linux only.</p>