#!/usr/local/bin/perl # # setrights.pl # # This script runs recursively on one of your dirs and sets regular files # access modes and directories access modes. You can change the modes by # modifying the patterns # Run "program -h" to see the run options # # Last modified: 3/21/97 # Author: Bekman Stas # # Set here the pattern extensions of your files/directories to change their mode @PATTERNS="*"; $file_perm=0640; # -rw-r----- $dir_perm=0750; # -rwxr-x--- $0 =~ s/^.*\///; # cut the basename of the command # Usage if (($ARGV[0] ne "-r") && ($ARGV[0] ne "-s")) { print "Usage: $0 [-hrs] -h this help -r recursive -s only in CWD\n"; exit(0); } # Change modes only in the directory the script was called from if ($ARGV[0] eq "-s") { &rights(); exit(0); } # Perl comes here only if you type "command -r" # Here we will run recursively thru the subdirs &recursive(); # Subroutine right changes the rights rwx for the files and dirs sub rights { foreach $entity (<*>) { if (-d $entity) { print "Doing dir: $entity\n"; chmod $dir_perm, $entity; } else { print "Doing file: $entity\n"; chmod $file_perm, $entity; } } } # Subroutine "recursive" goes recursively down at the dir tree and # calls "rights" sub. After comming to the end it's coming back up # at the tree. sub recursive { &rights(); foreach $dir (<*>) { if (-d $dir) { chdir $dir; &recursive(); chdir ".."; } } }