【问题标题】:What do {} and \ mean in 'sudo find /var/www/html -type d -exec chmod g+s {} \;''sudo find /var/www/html -type d -exec chmod g+s {} \;' 中的 {} 和 \ 是什么意思
【发布时间】:2017-01-02 20:47:21
【问题描述】:

我正在运行命令sudo find /var/www/html -type d -exec chmod g+s {} \; 来自here

那里说“我们可以通过键入上述命令在 WordPress 安装中的每个目录上设置 setgid 位”。 问题是{}/ 是什么意思?

运行find --help 得到Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec|time] [path...] [expression]...

所以上面的标志似乎与[path...] [expression]有某种关系,但它们的含义并不清楚。

【问题讨论】:

  • 你忘记了结尾的;

标签: linux bash shell gnu gnu-findutils


【解决方案1】:

如果您查看find 的手册页,您会看到-exec 将为找到的每个结果执行命令。它将通过\;判断命令的结束

它还将插入在{} 找到的目录的名称。所以上面的命令说找到/var/www/html下的每个目录并在上面执行chmod g+s

摘自手册页:

-exec utility [argument ...] ;
         True if the program named utility returns a zero value as its exit status.  Optional arguments may be passed to the utility.  The expression must be terminated by a semicolon (``;'').  If you invoke
         find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator.  If the string ``{}'' appears anywhere in the utility name or the arguments it is
         replaced by the pathname of the current file.  Utility will be executed from the directory from which find was executed.  Utility and arguments are not subject to the further expansion of shell pat-
         terns and constructs.

【讨论】:

    【解决方案2】:

    {} 是找到的文件的占位符。而; 标志着find-exec 选项执行的命令结束。反斜杠对分号进行转义,以便 shell 不会将其解释为元字符。

    【讨论】:

    • 反斜杠不会标记传递给-exec的命令的结束,分号会。反斜杠只是防止 shell 将其解释为对 sudo 的调用结束。
    • @chepner:这很容易解决……
    • @gniourf_gniourf 我修正了错别字,而不是错误的解释。
    • @chepner:我会在不太困难的情况下修复这两个问题(并且我也会修复(缺少)引号)。
    • 感谢修复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    相关资源
    最近更新 更多