转载:Linux目录文件的权限查看与修改

#######################################
#                                                                                       #
#     遍历所有目录修改文件权限                                  #
#     Input param:                                                           #
#         1,需修改的目录路径                                          #
#         2,修改后的权限                                                  #
#     Author: CaiLei                                                        # 
#######################################
#############遍历函数##################
LS_DIR()
{
   P=$1
   for DIR in `ls -l |awk {'print $9'}`  #遍历当前目录
   do
    if [ -d $DIR ]    #判断是否为目录
    then     #TRUE:进入该目录并且修改文件权限,循环进入该目录的子目录继续修改
       cd $DIR
       if [ `ls -A|wc|awk {'print $1'}` = 0  ] #判断目录是否为空,如为空返回上级目录
       then
          cd ../
       else
          chmod $P *
          LS_DIR $P    #递归调用
          cd ../
       fi
    else     #FLASE:修改该文件权限
       chmod $P $DIR > /dev/null
    fi
   done
}

###############主程序##################
INPUT_DIR=$1    #输入需要遍历的目录路径
cd $INPUT_DIR    #进入该目录
LS_DIR $2    #运行函数 

转载出处:

https://blog.csdn.net/andylei_cai/article/details/2132903

https://www.cnblogs.com/sxdcgaq8080/p/7498906.html

http://zhaoyuqiang.blog.51cto.com/6328846/1214718

原文地址:https://www.cnblogs.com/yaohuimo/p/10901373.html