0

sudo find /var/www/html -type d -exec chmod g+s {} \;这里运行命令

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

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

因此,上述符号似乎与 有某种关系[path...] [expression],但它们的含义尚不清楚。

4

2 回答 2

3

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

于 2017-01-02T20:53:44.627 回答
3

如果您查看手册页,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.
于 2017-01-02T20:53:54.690 回答