如何在 find 命令中使用 -exec 选项

xia*_*jie 3 command-line bash scripts compiling compiz

我想compiz用我的大脑双手解决一些问题。

顺便说一句,我输入了以下命令以compiz在 Ubuntu 12.04 中从源代码构建

find /opt/compiz-built/share/gconf/schemas -exec gconftool-2 --install-schema-file={};
Run Code Online (Sandbox Code Playgroud)

我在http://www.brazzi64.net/blog/building-compiz-from-source-in-ubuntu-12-04/提到了那个命令

并显示以下消息。

如何-exec在 find 命令中使用选项,我想这是我的错误。

Oli*_*Oli 6

您快到了。你需要\;在最后让 find 知道命令的结尾在哪里。

find /opt/compiz-built/share/gconf/schemas -exec gconftool-2 --install-schema-file={} \;
Run Code Online (Sandbox Code Playgroud)

对于一次可以使用多个参数的命令(例如,如果您只想stat使用每个文件名),您可以\+改用。这将构建一个复合参数,它可以更快地执行,因为它不会为每个文件分叉:

find . -exec stat {} \+
Run Code Online (Sandbox Code Playgroud)

不过,这不适用于您的示例。


只是一个测试工具来突出不需要引号:

$ mkdir 1 2 1\ 2               # makes three directories
$ touch {1,2}/single           # puts a file in each of the two singles
$ touch 1\ 2/COMBO             # puts a file in the dir with a space
$ find -type d -exec ls {} \;
1  1 2  2
single
single
COMBO
Run Code Online (Sandbox Code Playgroud)

如果它不为我们处理报价,我们会看到这个而不是 COMBO:

1:
correct

2:
correct
Run Code Online (Sandbox Code Playgroud)