-4

I have seen find commands as follows, and wonder on the difference between them.

find . -exec COMMAND {} \;
find . -exec COMMAND {} \+
find . -exec COMMAND {} +
Vera
  • 1,173
  • 4
  • 17
  • Do `\+` and `+` behave the same way? – Vera Oct 24 '21 at 05:40
  • 1
    `\+` in most shells is the same as `'+'` or `"+"`, backslash is a quoting operator in the shell syntax, so you end up with a quoted `+`. `+` being not a special character in the shell syntax, quoting is unnecessary, so it's the same as `+`. It's different for `;`. Where `\;`, `';'` or `";"` are three ways to pass a literal `;` to `find`, but unquoted `;` is special in the shell syntax: it's used to separate commands. – Stéphane Chazelas Oct 24 '21 at 06:18
  • Is `+` a special character in gnu bash? – Vera Oct 24 '21 at 06:38

1 Answers1

-3

There are two syntaxes for find exec.

find . -exec [cmd] {} \;

{} Is a placeholder for the result found by find

; Says that for each found result, the command cmd is executed once with the found result.

It is executed like this: cmd result1; cmd result2; ...; cmd result N

find . -exec [cmd] {} \+

{} Is a placeholder for the result found by find

+ Says that for all found results, the command cmd is executed with all the found results.

It is executed like this: cmd result1 result2 ... result N

when we should use find exec ; other than +

The tool run by -exec does not accept multiple files as an argument

Running the tool on so many files at once might use up too much memory

We want to start getting some results as soon as possible, even though it will take more time to get all the results

DOS HASAN
  • 118
  • 2
  • 1
    Exact copy of [10 Linux Find Exec examples - Advanced Part](https://www.howtouselinux.com/post/linux-find-exec-examples-advanced-part) – Greenonline Oct 24 '21 at 03:47
  • Much appreciated. Does `+` behave the same way as `\+`? – Vera Oct 24 '21 at 03:47
  • @Greenonline Smart dude. :) – Vera Oct 24 '21 at 03:52
  • 1
    DOS HASAN, please see the [How to reference material written by others](https://unix.stackexchange.com/help/referencing) page in our Help Center and follow its advice: *Do not copy the complete text of external sources; instead, use their words and ideas to support your own. And always give proper credit to the author and site where you found the text, including a direct link to it.* – Jeff Schaller Oct 25 '21 at 11:17