#!/bin/sh if [ "$4" != "sub" ] then if [ x"$4" != x ] then echo "ERROR: in parameters" exit 10 fi echo "(C) PIF 2000" echo "Change permissions for subdirectories" echo " " fi dirmode=$1 filemode=$2 dirpath=$3 if [ "$4" != "sub" ] then if [ x"$dirpath" == x ] then echo "This program will change access mode for directories and files recursively" echo "Usage: chsub dirmode filemode dir" echo " dirmode - directory mode" echo " filemode - file mode" echo " dir - the name of the directory or file" echo " " echo "Example: chsub /tmp 755 644" exit 0 fi fi if [ $# -le 2 ] then echo "ERROR: in parameters" echo "Type chsub for help" exit 1 fi if [ -e "$dirpath" ] then chmod $dirmode "$dirpath" else echo "ERROR: $dirpath does not exists!" exit 11 fi if [ $? -ne 0 ] then echo "ERROR: in chmod" exit 2 fi for i in `ls -1a "$dirpath"` do if [ "$i" != "." ] then #Skip file "." if [ "$i" != ".." ] then #Skip file ".." if [ -d "$dirpath/$i" ] then #If $dirpath/$i is a directory echo "Directory $dirpath/$i" chmod "$dirmode" "$dirpath/$i" >/dev/null 2>&1 $0 "$dirpath/$i" "$dirmode" "$filemode" sub else #if $dirpath/$i is not a directory echo " File $dirpath/$i" chmod "$filemode" "$dirpath/$i" >/dev/null 2>&1 fi fi fi done