title: Find and rename multiple files using a bash script in Linux
body: <p>As an example, in a directory <code>/home/hel/files/</code> are thousends of files and hundreds of directories.
  An application saves there its output files with special characters in the file names.
  I want to replace these special characters with underscores in all file names. e.g. <code>-:"&lt;&gt;@</code></p>
  
  <p>I wrote a bash script which simply repeats a command to rename the files using Linux/Unix 'rename'.</p>
  
  <p>Example: file name: <code>rename.sh</code></p>
  
  <pre><code>#!/bin/bash
  rename "s/\'/_/g" *
  rename 's/[-:"&lt;&gt;@\,&amp;\s\(\)\[\]?!–~%„“;│\´\’\+#]/_/g' *
  rename 'y/A-Z/a-z/' *
  rename 's/\.(?=[^.]*\.)/_/g' *
  rename 's/[_]{2,}/_/g' *
  </code></pre>
  
  <p>I execute the following find command:</p>
  
  <pre><code>find /home/hel/files/ -maxdepth 1 -type f -execdir /home/hel/scripts/rename.sh {} \+
  </code></pre>
  
  <p>Now the issue:</p>
  
  <p>This works fine, except the fact, that it renames subdirectories too, if they have the searched characters in their name.</p>
  
  <p>The find command searches just for files and not for directories.</p>
  
  <p>I tried some other find variations like:</p>
  
  <pre><code>find /home/hel/files/ -maxdepth 1 -type f -execdir sh /home/hel/scripts/rename.sh {} \+
  find /home/hel/files/ -maxdepth 1 -type f -execdir sh /home/hel/scripts/rename.sh {} +
  find /home/hel/files/ -maxdepth 1 -type f -execdir sh /home/hel/scripts/rename.sh {} \;
  </code></pre>
  
  <p>They are all working, but with the same result.</p>
  
  <p>What is not working:</p>
  
  <pre><code>find /home/hel/files/ -maxdepth 1 -type f -exec sh /home/hel/scripts/rename.sh {} \+
  </code></pre>
  
  <p>This one is dangerous, because it renames the directories and files in the current directory, where you call the find command too.</p>
  
  <p>Maybe one has an idea, why this happens or has a better solution.</p>