linux - Bash:如何将 'find' 选项保存到变量中

标签 linux bash find

我需要chownchmod 一些目录和文件。为了不总是重复查找过滤器,我需要将它们保存到一个变量中。

以下代码产生语法错误:“(” 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/

相关文章:

windows - 从 Windows 上的 bash 脚本运行 Openssl - 主题不以 '/' 开头

linux - 当本地相同的脚本成功时,通过 ssh 运行脚本失败

linux - bash 从原始文件中提取路径复制文件

sql - 带查找功能的 Rails SQL 查询

linux - 连接 lapack 时遇到问题

linux - 线程实现会降低性能

python - 如何在 bash 中将前缀组合到 ls 的输出?

linux - 简单的原始数据包捕获和发送程序

python - Pecl/Python : unsupported locale setting - Ubuntu 13. 10

bash - 设置 Linux 上查找的默认选项