我需要chown
和chmod
一些目录和文件。为了不总是重复查找过滤器,我需要将它们保存到一个变量中。
以下代码产生语法错误:“(” unexpected
findOpts=( \( -path ./.git -o -name .gitignore \) -prune -o )
find . "${findOpts[@]}" chown www-data:www-data {} \+
find . "${findOpts[@]}" -type d -exec chmod 550 {} \+
find . "${findOpts[@]}" -type f -exec chmod 440 {} \+
最佳答案
由于您的 chmod 调用只是在目录上启用 x
位并在文件中禁用它,您可以使用 X
(大写 x
)在 chmod 中(首先清除它们之后):
chmod a=,ug+rX file[..]
此外,您可以在 find
中使用多个 -exec
(至少在 GNU find
中),因此您可以只执行一次 find,无需保存选项:
find . [your filters here] \
-exec chown www-data:www-data {} \; \
-exec chmod a=,ug+rX {} \;
关于linux - Bash:如何将 'find' 选项保存到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31402389/