-2

In this command

find . -xdev -type f \( -mtime 0 -or -mtime 1 \) -exec cp -aPv "{}" $dest.new \;

Do the parentheses in \( -mtime 0 -or -mtime 1 \) mean precedence?

Are they required to be preceded by backslash? Why?

Tim
  • 101,790

1 Answers1

1

Yes, the parentheses mean precedence, and the backslashes are required to escape them for the shell. From man find.

   ( expr )
          Force  precedence.   Since  parentheses  are special to the shell, you will normally need to quote them.  Many of the examples in this manual page use backslashes for this purpose: `\(...\)'
          instead of `(...)'.

So in your example, they are just to group the -or statement. There's more information here on order of precedence.

Sparhawk
  • 19,941
  • 1
    Thanks. If not escaped, how does the shell interpret the parentheses? – Tim Feb 13 '17 at 05:35
  • 3
    @Tim you could just try it yourself... – Stephen Kitt Feb 13 '17 at 05:51
  • @Tim The parentheses just get directly interpreted by the shell. Most (all?) of the time the shell would spawns a subshell, which would break your find command. That's how it works in bash, zsh, etc. at least… – Sparhawk Feb 13 '17 at 05:53
  • 1
    @Sparhawk most of the time it results in a syntax error; the shell doesn't spawn a subshell, it tries to parse the command and stops at the unexpected (. – Stephen Kitt Feb 13 '17 at 06:11
  • @StephenKitt Yes, I meant that the shell (probably) interprets it as a command to spawn a subshell, and fails because the line is just… wrong. – Sparhawk Feb 13 '17 at 06:13