#!/bin/bash
chmodPath()
{
Permission=$1
TmpPath=$2
Result=`echo $Permission | grep -E [0-7]{3}`
if [ "$Result" == "" ]; then ##match
Result=`echo $Permission | grep -E "^/+[rwx]{1,3}$"`
if [ "$Result" == "" ]; then
echo "the permission format error! like this: 777 or +rw"
return 1
fi
fi
if [ ! -e $TmpPath ]; then
echo "the path $TmpPath is not existed. please check it."
return 1
fi
while [[ "$TmpPath" != "/" && "$TmpPath" != "." ]]
do
chmod $Permission $TmpPath
TmpPath=`dirname $TmpPath`
done
return 0
}
if [ $# -ne 2 ]; then
echo "usage: $0 permission path"
exit 1
fi
chmodPath $1 $2
exit
【shell】统一修改某一路径上目录的权限
最新推荐文章于 2022-10-27 18:39:05 发布