分享自己的第一个shell脚本,逻辑可能不严谨,望大家多多指点。
要求:递归将所有的文件赋权为440,目录赋权为550。
代码如下:
```bash
在这里插入代码片
#!/bin/bash
#modify files 440(r--r-----)
#modify directory 550(r-xr-x---)
#Recursively finds the files in the current directory
function func() {
first=`ls $1`
for obj in $first
do
address=`echo $1/$obj`
if [ -d $address ]
then
chmod 550 $address
cd $address
if [ `ls -A | wc | awk '{print $1}'` != 0 ]
then
func $address
else
echo "No directory was found under current path"
fi
elif [ -f $address ]
then
chmod 440 $address
else
echo "No file or directory was found under current path"
fi
done
}
pwd=`pwd`
func $pwd
以上就是这次的shell小脚本,逻辑可能不太严谨,欢迎各位提出宝贵意见,谢谢!