简体   繁体   English

find命令末尾的\\;和+之间有什么区别?

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

These are bash commands that are used to convert tabs to spaces. 这些是bash命令,用于将制表符转换为空格。 Here's the link to the original stackoverflow post. 这是原始stackoverflow帖子的链接

This one uses \\; 这个用\\; at the end of the command 在命令末尾

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

This one uses + instead of \\; 这个用+代替\\; .

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

What exactly is the difference between the two? 两者之间到底有什么区别?

The \\; \\; or + is not related to bash. +与bash无关。 It's an argument to the find command, specifically to find 's -exec option. 这是find命令的参数,专门用于find-exec选项。

find -exec uses {} to pass the current file name to the specified command, and \\; find -exec使用{}将当前文件名传递给指定的命令,并\\; to mark the end of the the command's arguments. 标记命令参数的结尾。 The \\ is needed because ; 之所以需要\\是因为; by itself is special to bash; 本身就是特殊的抨击; by typing \\; 通过输入\\; , you can pass a literal ; ,您可以传递文字; character as an argument. 字符作为参数。 (You can also type ';' or ";" .) (您也可以输入';'";" 。)

The + symbol (no \\ needed because + is not special to bash) causes find to invoke the specified command with multiple arguments rather than just once, in a manner similar to xargs . +符号(没有\\必要的,因为+是不是特别的bash)的原因find调用指定的命令使用多个参数,而不是只有一次,在类似的方式xargs

For example, suppose the current directory contains 2 files named abc and xyz . 例如,假设当前目录包含2个名为abcxyz文件。 If you type: 如果输入:

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

it invokes the echo command twice, producing this output: 它两次调用echo命令,产生以下输出:

./abc
./xyz

If you instead type: 如果您输入:

find . -type f -exec echo {} +

then find invokes echo just once, with the following output: 然后find仅调用一次echo ,并显示以下输出:

./xyz ./abc

For more information, type info find or man find (if the documentation is installed on your system), or you can read the manual online at http://www.gnu.org/software/findutils/manual/html_node/find_html/ 有关更多信息,请键入info findman find (如果您的系统上已安装文档),或者您可以在http://www.gnu.org/software/findutils/manual/html_node/find_html/在线阅读该手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM