加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
220.save_perm.sh 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
大吉客 提交于 2023-08-04 15:03 . 1.修改,修改220
#!/bin/bash
OUTDIR=$PWD/perm
top_d=${OUTDIR}
mkdir -p $top_d
rm -rf $top_d/*
save_perm()
{
typ=$1
key=$2
fil_f=${OUTDIR}/${key}.${typ}.f
fil_p=${OUTDIR}/${key}.${typ}.p
if [ "xfile" == "x$typ" ]; then
find $key -maxdepth 5 -type f >> ${fil_f}
elif [ "xfolder" == "x$typ" ]; then
find $key -maxdepth 5 -type d >> ${fil_f}
else
return
fi
while read -r line
do
if [ -e "$line" ]; then
pm=$(stat -c "%A" "$line")
nm=$(stat -c "%n" "$line")
uid=$(stat -c "%u" "$line")
gid=$(stat -c "%g" "$line")
export need_save_perm=0
have_s=$(echo $pm|grep -i s)
if [ -n "$have_s" ]; then
export need_save_perm=1
fi
if [ "x0" != "x$uid" ]; then
export need_save_perm=1
fi
if [ "x0" != "x$gid" ]; then
export need_save_perm=1
fi
if [ ! -z "$nm" ] ; then
if [ "x1" == "x$need_save_perm" ]; then
echo "$pm $uid $gid $nm"
echo "$pm $uid $gid $nm" >> $fil_p
fi
fi
fi
done < $fil_f
}
save_perm file /etc
save_perm folder /etc
save_perm file /bin
save_perm folder /bin
save_perm file /sbin
save_perm folder /sbin
save_perm file /lib
save_perm folder /lib
save_perm file /usr
save_perm folder /usr
save_perm file /var
save_perm folder /var
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化