LoginSignup
151
124

More than 5 years have passed since last update.

find の -exec optionの末尾につく \; と + の違い。

Last updated at Posted at 2013-09-11

Emacsの find-grep で出てくるコマンド find . -type f -exec grep -nH -e {} + の最後の + を見たことなかったのでStack Overflowで質問してみました。

まず「お前はちゃんと man を読め。」と怒られましたが、わかりやすいサンプル付きで説明がもらえたので良しとします。いつもありがとうございます。

-exec {} \;-exec {} + の違い

まず \; の 頭についてるバックスラッシュはこれがないとセミコロンがシェルのコントロール文字列だと判別されるためについてるだけです。

そして肝心の違いですが -exec {} \; は find で見つかったそれぞれのファイルを別々にコマンドに渡して、 -exec {} + は可能な限りまとめて渡します。

言葉の説明だけだとよくわからないでしょうから実際の例を見てみましょう。

$ mkdir test
$ touch test/{a,b}
$ find test -exec echo foo {} \;
foo test
foo test/a
foo test/b
$ find test -exec echo foo {} +
foo test test/a test/b

あー、なるほど。

参考

emacs - find -exec should end with \; or +? - Super User
http://superuser.com/questions/643798/find-exec-should-end-with-or/643802?noredirect=1#643802

151
124
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
151
124