2

For the command structure -exec command {} \;,i got info in man find.

  1. {} means selected files.
  2. ; means trminate the argument.
  3. \; escaped to protect them from expansion by the shell.

In the paragraph related to -exec command {} +.

 -exec command {} +
              This  variant  of the -exec action runs the specified command on
              the selected files, but the command line is built  by  appending
              each  selected file name at the end; the total number of invoca‐
              tions of the command will  be  much  less  than  the  number  of
              matched  files.   The command line is built in much the same way
              that xargs builds its command lines.  Only one instance of  `{}'
              is  allowed  within the command, and (when find is being invoked
              from a shell) it should be quoted (for example, '{}') to protect
              it  from  interpretation  by shells.  The command is executed in
              the starting directory.  If any invocation  returns  a  non-zero
              value  as exit status, then find returns a non-zero exit status.
              If find encounters an error, this can sometimes cause an immedi‐
              ate  exit, so some pending commands may not be run at all.  This
              variant of -exec always returns true.

It never say something on + ,What does + mean in the bash -exec command {} +?
It means to terminate the argument such as ;?
+ means plus such as 3+5=8 or concatenate , to join two strings into one such as s1+s2.
It is a strange thing to assign a meaning terminate the argument for +.

1

1 Answer 1

3

It has nothing to do with Bash, it's a part of find syntax. The command has to know where the -exec action ends. It ends at ; or at +. Depending on the terminating character, a proper variant of -exec action is used.

Why were these two characters chosen for this purpose? I don't know. Some way to end -exec statement was a must and somebody chose ; and +. Now the characters are parts of POSIX standard when it comes to the find command.

We can only guess that ; was chosen because it can also terminate a command in a shell, so the purpose is similar. For this reason, however, ; that needs to be seen by find has to be treated specially in the shell, hence \; (';' or ";" also works). There's no such problem with +.

Technically almost any other string could have been chosen instead of + (the same with ;). Note that -exec, {}, + and ; (after it passes the shell thanks to escaping or quoting), possible tests or actions like -type or -print – they all are arguments to find; they become meaningful when find processes them, their meaning comes from how find was invented.

To summarize:

  1. It's about find, not about bash.
  2. The tool supports two slightly different -exec actions.
  3. To tell them apart we use two different arguments that terminate -exec statement; it's a design choice.
  4. These two different arguments are ; and +; it's a design choice.
  5. These choices could have been made differently. Even if there is a story behind + (which I don't know), it's trivia, not something really meaningful. I can only speculate {} + is for "one argument or more" like 10+ sometimes means "ten or more".

Broader insight

+ means plus such as 3+5=8 or concatenate, to join two strings into one such as s1+s2. It is a strange thing to assign a meaning terminate the argument for +.

How about

> means "greater than"… It is a strange thing to assign a meaning "redirect" for >.

"+ means plus" is not from God. Somebody decided, others followed and the symbol stuck.

  • Somebody decided + means "plus" in mathematics.
  • Somebody decided > means "greater than" in mathematics.
  • Somebody decided > redirects in a shell.
  • Somebody decided + terminates -exec in find context.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .