find命令下排除部分目录修改权限

#!/bin/bash
# 项目文件夹、文件权限修改
# 批量修改文件夹或者文件的权限时,需要先忽略掉可写文件夹('./bootstrap/cache''./public/attachments''./public/images''./storage')

# 忽略 './bootstrap/cache' './public/attachments' './public/images' './storage' 文件夹及子文件
ignore_path="-not -path './bootstrap/cache' -and -not -path './bootstrap/cache/*' -and -not -path './public/attachments' -and -not -path './public/attachments/*' -and -not -path './public/images' -and -not -path './public/images/*' -and -not -path './storage' -and -not -path './storage/*'"
find_dirs="find . -type d $ignore_path"
find_files="find . -type f $ignore_path"
# 修改文件夹权限为 555
chmod_dirs="sudo $find_dirs -exec chmod 555 {} ;"
# 修改文件权限为 444
chmod_files="sudo $find_files -exec chmod 444 {} ;"


#echo $chmod_dirs
#echo $chmod_files
eval $chmod_dirs; eval $chmod_files
原文地址:https://www.cnblogs.com/mikeluwen/p/8706893.html