如何检查目录及其所有递归内容的权限?
How do I check permissions of a directory and all of its recursive content?
我创建了一个简单的 bash 脚本来检查目录是否具有给定的权限,然后执行它的任务。
if [ `stat -c "%a" my_directory` != 777 ]; then
# script to be executed
fi
现在,这很好用,但它只检查给定目录的权限。如果权限设置为不同于 777
.
,我还需要递归检查 my_directory
的所有内容
换句话说,只要 my_directory
中的单个文件或目录的权限未设置为 777
,此脚本就应该 运行。如果此目录中的所有内容都可以完全访问,则脚本不应 运行.
如何修改我的脚本以使其以这种方式工作?
感谢 Jordanm 的建议,我修改了我的脚本
checkfiles=0
declare -i checkfiles
for file in `find my_directory ! -perm 777`
do
checkfiles+=1
done
if [ $checkfiles != 0 ]; then
# script to be executed
fi
我创建了一个简单的 bash 脚本来检查目录是否具有给定的权限,然后执行它的任务。
if [ `stat -c "%a" my_directory` != 777 ]; then
# script to be executed
fi
现在,这很好用,但它只检查给定目录的权限。如果权限设置为不同于 777
.
my_directory
的所有内容
换句话说,只要 my_directory
中的单个文件或目录的权限未设置为 777
,此脚本就应该 运行。如果此目录中的所有内容都可以完全访问,则脚本不应 运行.
如何修改我的脚本以使其以这种方式工作?
感谢 Jordanm 的建议,我修改了我的脚本
checkfiles=0
declare -i checkfiles
for file in `find my_directory ! -perm 777`
do
checkfiles+=1
done
if [ $checkfiles != 0 ]; then
# script to be executed
fi