Skip to main content
added 28 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

I am not sure what your intention is (you didn't make that clear), but if it's to chmod to 700 all the files that match the pattern, then, except for your typo (;\ instead of \;), your command seems to work as intended.

However:

when it finds a file containing that string grep -q gives me 0 so another exec executes but should not.

Yes, it should do. 0 means success means true, so find continues to evaluate its expression, and the second -exec runs. 1 (or any value other than 0) would mean failure would mean false, so find would short-circuit its evaluation (there is an implicit logical AND between juxtaposed expressions) so the second -exec does not run.

Why does it work

Check the manpage for GNU find:

expr1 expr2

Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.

I am not sure what your intention is (you didn't make that clear), but if it's to chmod to 700 all the files that match the pattern, then, except for your typo (;\ instead of \;), your command seems to work as intended.

However:

when it finds a file containing that string grep -q gives me 0 so another exec executes but should not.

Yes, it should do. 0 means success means true, so find continues to evaluate its expression, and the second -exec runs. 1 would mean failure would mean false, so find would short-circuit its evaluation (there is an implicit logical AND between juxtaposed expressions) so the second -exec does not run.

Why does it work

Check the manpage for GNU find:

expr1 expr2

Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.

I am not sure what your intention is (you didn't make that clear), but if it's to chmod to 700 all the files that match the pattern, then, except for your typo (;\ instead of \;), your command seems to work as intended.

However:

when it finds a file containing that string grep -q gives me 0 so another exec executes but should not.

Yes, it should do. 0 means success means true, so find continues to evaluate its expression, and the second -exec runs. 1 (or any value other than 0) would mean failure would mean false, so find would short-circuit its evaluation (there is an implicit logical AND between juxtaposed expressions) so the second -exec does not run.

Why does it work

Check the manpage for GNU find:

expr1 expr2

Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.

Source Link
Celada
  • 45.7k
  • 5
  • 100
  • 108

I am not sure what your intention is (you didn't make that clear), but if it's to chmod to 700 all the files that match the pattern, then, except for your typo (;\ instead of \;), your command seems to work as intended.

However:

when it finds a file containing that string grep -q gives me 0 so another exec executes but should not.

Yes, it should do. 0 means success means true, so find continues to evaluate its expression, and the second -exec runs. 1 would mean failure would mean false, so find would short-circuit its evaluation (there is an implicit logical AND between juxtaposed expressions) so the second -exec does not run.

Why does it work

Check the manpage for GNU find:

expr1 expr2

Two expressions in a row are taken to be joined with an implied "and"; expr2 is not evaluated if expr1 is false.