title: Get the filename from bash script recursively using find
body: <p>I am trying retrieve the filename from the find command recursively. This command prints all the filenames with full path</p>
  
  <pre><code>&gt; for f in $(find -name '*.png'); do echo "$f";done          
  &gt; ./x.png
  &gt; ./bg.png
  &gt; ./s/bg.png
  </code></pre>
  
  <p>But when i try to just get the name of the file using these commands, it prints</p>
  
  <pre><code>for f in $(find -name '*.png'); do echo "${f##*/}";done                                                                                                       
  bg.png
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for f in $(find -name '*.png'); do echo $(basename $f);done   
  bg.png
  </code></pre>
  
  <p>It omits other 2 files. I am new to shell scripting. I couln't figure out whats wrong with this one.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>THis is what i have actually wanted.</p>
  
  <ol>
  <li>I want to loop through a directory recursively and find all png images</li>
  <li>send it to pngnq for RGBA compression</li>
  <li>It outputs the new file with <code>orgfilename-nq8.png</code></li>
  <li>send it to pngcrush and rename and generate a new file (org file will be overwritten )</li>
  <li>remove  new file </li>
  </ol>
  
  <p>i have a code which works on a single directory</p>
  
  <pre><code>for f in *.png; do pngnq -f -n 256 "$f" &amp;&amp; pngcrush "${f%.*}"-nq8.png "$f";rm "${f%.*}"-nq8.png; done
  </code></pre>
  
  <p>I want to do this recursively</p>