title: Linux find -exec permission denied
body: <p>I wrote a shell script iterating through files and ordering their contents and saving the new order back to the file.</p>
  
  <pre><code>#!/bin/sh
  
  for i in "$@"; do
      sort $i -k2 -o $i
  done
  </code></pre>
  
  <p>The files to be sorted are chosen with the <code>find</code> command like so:</p>
  
  <pre><code>find . -regex '&lt;myregex&gt;' -exec ./mysort.sh {} +
  </code></pre>
  
  <p>I wrote the script and tried it out one machine as a specific user and then copied it over to another machine using root privileges. So now the files has <code>chown root:root</code> as have all the files I wand to search through.</p>
  
  <p>So now the files to be sorted are located in the same folder as the mysort.sh and when I try to execute the find with -exec i get</p>
  
  <p><code>find: './mysort.sh': Permission denied</code></p>
  
  <p>I tried moving the script to a subfolder and executing the command with <code>-exec ./folder/mysort.sh</code> or moving it to a higher level folder and executing it with <code>-exec ../mysort.sh</code>. I always get different variations of Permission denied errors. </p>