Linux环境部署web应用按类型修改文件权限

#!/bin/bash
# Define a function
list_dir(){
# Traversal parameter $1
for file in $1/*
do
    # If it is a directory then treat it ,after it's treated traverse it
    if [ -d $file ] ; 
    then 
        echo "$file is directory"
        chmod 750 $file
        echo "Directory $file changed to 750 "
        list_dir $file
    elif [ -f $file ] ; 
    then 
        suffix=`echo -n $file|awk -F. '{print $NF}'` #获取$file文件的后缀
    #下面case语句对文件权限进行修改 
        case $suffix in
            "zip") chmod 750 $file 
                 echo "file $file changed to 750"
            ;;
            "sh") chmod 750 $file 
                 echo "file $file changed to 750"
            ;;
            "jar") chmod 750 $file
                 echo "file $file changed to 750"
            ;;
            "bat") chmod 750 $file
                 echo "file $file changed to 750"
            ;;
            "rpm") chmod 750 $file
                 echo "file $file changed to 750"
            ;;
            "so") chmod 750 $file
                 echo "file $file changed to 750"
            ;;
            "tar") chmod 750 $file
                 echo "file $file changed to 750"
            ;;
            *)chmod 640 $file
                 echo "Regular file $file changed to 640"
            ;;
        esac
           list_dir $file
       fi
done
}

# If there is parameter to traverse the specified directory, 
# otherwise the current directory traversal
if [ $# -gt 0 ]

then
    list_dir "$1"
else
    list_dir "."
fi


#edit jre-java permission to 750
project_path=$(cd $(dirname $0); pwd)

echo "jre-java changed permission to 750"
find $project_path/jre/bin/ -name "java"|xargs chmod 750 *

  

posted @ 2021-10-25 17:01  yaohuimo  阅读(32)  评论(0编辑  收藏  举报