-4

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

find . -exec COMMAND {} \;
find . -exec COMMAND {} \+
find . -exec COMMAND {} +
3
  • Do \+ and + behave the same way?
    – khin
    Oct 24, 2021 at 5: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. Oct 24, 2021 at 6:18
  • Is + a special character in gnu bash?
    – khin
    Oct 24, 2021 at 6:38

1 Answer 1

-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

4
  • 1
    Exact copy of 10 Linux Find Exec examples - Advanced Part Oct 24, 2021 at 3:47
  • Much appreciated. Does + behave the same way as \+?
    – khin
    Oct 24, 2021 at 3:47
  • @Greenonline Smart dude. :)
    – khin
    Oct 24, 2021 at 3:52
  • 1
    DOS HASAN, please see the How to reference material written by others 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, 2021 at 11:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.