Nov 132009
 

If you ever recursively chmod public_html to something terrible, this script will restore files back to their typical/default permissions.

cd to the public_html directory, and run the command:

perl 

Hit enter, and then paste this code:

#!/usr/bin/perl -w
sub scanDir {
  my $dir = shift;

  opendir (DIR, $dir);
  foreach my $file (readdir(DIR)) {
    next if $file eq ".";
    next if $file eq "..";

    if (-d "$dir/$file") {
      print "chmod directory: 0755 ($dir/$file)\n";
      chmod (0755, "$dir/$file");
      &scanDir ("$dir/$file");
    }
    else {
      if ($file =~ /\.(cgi|pl|plx|plex)$/i) {
        print "chmod CGI file: 0755 ($dir/$file)\n";
        chmod (0755, "$dir/$file");
      }
      else {
        print "chmod file: 0644 ($dir/$file)\n";
        chmod (0644, "$dir/$file");
      }
    }
  }
  closedir (DIR);
}

&scanDir(".");
__END__

If it doesn’t execute right away, hit “Enter” again after the __END__ line.

These will also work

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

 Posted by at 6:03 am