查找命令末尾的“\;”和“+”有什么区别?

What's the difference between `\;` and `+` at the end of a find command?

这些 bash 命令用于将制表符转换为空格。 这是原始 Whosebug post.

link

这个在命令末尾使用\;

find /path/to/directory -type f -iname '*.js' -exec sed -ie 's|\t|    |g' '{}' \;

这个使用 + 而不是 \;

find /path/to/directory -type f -iname '*.js' -exec sed -ie 's|\t|    |g' '{}' '+'

两者到底有什么区别?

\;+ 与 bash 无关。它是 find 命令的参数,特别是 find-exec 选项。

find -exec 使用 {} 将当前文件名传递给指定的命令,并使用 \; 标记命令参数的结尾。 \ 是必需的,因为 ; 本身 对 bash 的特殊;通过键入 \;,您可以传递文字 ; 字符作为参数。 (您也可以键入 ';'";"。)

+ 符号(不需要 \ 因为 + 不是 bash 的特殊符号)导致 find 调用带有多个参数的指定命令而不是一次,以类似于 xargs.

的方式

例如,假设当前目录包含 2 个名为 abcxyz 的文件。如果您键入:

find . -type f -exec echo {} \;

它调用 echo 命令两次,产生以下输出:

./abc
./xyz

如果您改为键入:

find . -type f -exec echo {} +

然后 find 调用 echo 一次,输出如下:

./xyz ./abc

有关更多信息,请键入 info findman find(如果您的系统上安装了文档),或者您可以在 http://www.gnu.org/software/findutils/manual/html_node/find_html/

在线阅读手册