title: Scan file or folder with bad permissions
body: <p>I'd just like to see a list of files and folders where folder &lt;> 755 and file &lt;> 644</p>
  
  <p>Is there a script that can recursively scan all files/folders on my web server for this info?</p>
  
  <p>My site got hacked, a bunch of files were set to 200 permissions, its a Joomla 1.5 site, so many files/folders, will take for ever to do this manually.</p>
  
  <p>Host at 1and1 and is a linux shared server</p>
  
  <p>I'm looking for a PHP script</p>
  
  <p><strong>SOLUTION (thanks Robert for info)</strong>
  For some reason on windows and linux folders return 55
  I got the function for perms from <a href="http://php.net/manual/en/function.fileperms.php" rel="nofollow">http://php.net/manual/en/function.fileperms.php</a></p>
  
  <pre><code>&lt;?php
  $path = realpath('.');
  $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),RecursiveIteratorIterator::SELF_FIRST);
  $c = 0;
  
  foreach($files as $name =&gt; $f){
          $perm = file_perms($f);
          if ($perm!="644" &amp;&amp; $perm!="755" &amp;&amp; $perm!="55") {
              $c++;
              echo "&lt;b&gt;".$perm."&lt;/b&gt; :: ";
              echo $f-&gt;getPathname()."&lt;br&gt;";
              if ($c==200) {exit();}
          }
  }
  
  function file_perms($file, $octal = false)
  {
      if(!file_exists($file)) return false;
      $perms = fileperms($file);
      $cut = $octal ? 2 : 3;
      return substr(decoct($perms), $cut);
  }
  ?&gt;
  </code></pre>