#!/bin/bash

if [ $# -ne "3" ] ;then
	echo "Change the directory, sub-directory and file with seperate permission mode"
	echo "Usage: chmmod 755 644 directory"
	exit
fi

dir_mode=$1
file_mode=$2
mod_dir=$3

#change the main directory first
chmod $dir_mode $mod_dir

cd $mod_dir

obj_list="`ls -R`"
for obj in $obj_list; do
	if [ `echo $obj|grep -c '^\.'` -gt 0 ] ;then
		#echo $obj is a dir
		cur_dir="`echo $obj|awk -F: '{print $1}'`"
		chmod $dir_mode $cur_dir
	else
		#echo $obj is file,cur_dir=$cur_dir chmod $dir_mode $cur_dir/$obj
		chmod $file_mode $cur_dir/$obj
	fi
done


