检查目录下 文件的权限-linux shell脚本
程序员文章站
2022-07-09 17:51:22
#!/bin/bash #History: #2019/07/23 Fsq #This Program will check Permissions on dir PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/ ......
#!/bin/bash
#history:
#2019/07/23 fsq
#this program will check permissions on dir
path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export path
read -p "please input your dir:" dir
if [ "$dir" == "" -o ! -d "$dir" ];then #检查目录是否存在
echo "this $dir is not exsit in system"
exit 1
fi
filelist=$(ls $dir) #列出该目录下的所有文件名
for filename in $filelist
do
perm=""
test -r "$dir/$filelist" && perm="$perm readable"
test -w "$dir/$filelist" && perm="$perm writable"
test -x "$dir/$filename" && perm="$perm executable"
echo "the file $dir/$filename's permission is $perm"
done