Web Permissions Script

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 {} \;

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.