'sudo find /var/www/html -type d -exec chmod g+s {} \;' 中的 {} 和 \ 是什么意思

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 {} \; 来自 here

据说"We can set the setgid bit on every directory in our WordPress installation by typing the above command"。 问题是 {}/ 是什么意思?

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

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

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

如果您查看 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.