2012年(9)
分类: LINUX
2012-08-16 22:30:12
#!/bin/bash
# 查看目录下文件权限的脚本..
echo -e "Please enter the need to look at the state of the directory\n
For Example : \033[31m /etc \033[0m"
read DST
echo -e "\033[31;43m -------------OUTPUT-------------\033[0m"
if [ -d $DST ];then
for FILE in $DST/*
do
FILEDIR=$(dirname $FILE)
FILENAME=$(basename $FILE)
################ read ###################
if [ -r $FILEDIR/$FILENAME ];then
if [ -w $FILEDIR/$FILENAME ];then
if [ -x $FILEDIR/$FILENAME ];then
echo -e "$FILEDIR/$FILENAME permission is \033[31m -rwx \033[0m "
else
echo -e "$FILEDIR/$FILENAME permission is \033[31m -rw- \033[0m"
fi
elif [ -x $FILEDIR/$FILENAME ];then
echo -e "$FILEDIR/$FILENAME permission is \033[31m -r-x \033[0m"
else
echo -e "$FILEDIR/$FILENAME permission is \033[31m -r-- \033[0m"
fi
############# write #######################
elif [ -w $FILEDIR/$FILENAME ];then
if [ -x $FILEDIR/$FILENAME ];then
echo -e "$FILEDIR/$FILENAME permission is \033[31m --wx \033[0m "
else
echo -e "$FILEDIR/$FILENAME permission is \033[31m --w- \033[0m"
fi
################# execute #######################
elif [ -x $FILEDIR/$FILENAME ];then
echo -e "$FILEDIR/$FILENAME permission is \033[31m ---x \033[0m"
################### OTHER ##################
else
echo -e "$FILEDIR/$FILENAME \033[31m No authority \033[0m"
fi
done
if [ "$?" == "0" ];then
echo -e "\033[31;43m -------------ls- $DST--- OUTPUT-------------\033[0m"
ls -l $DST
fi
else
echo "PLS input Effective directory"
fi