0

here is a simple script that I don't really understand:

#!/bin/bash
while read s; do
ssh -oStrictHostKeyChecking=no (connection to my servers) 'sudo find /path/to/main/directory -type f -exec chmod 755 {} +'
done < hosts_to_change.txt

without the + at the command it says chmod: missing operand after ‘755’. Could someone explain why I need to use the '+' and 755 is not enough?

2
  • 2
    See man 1 find, -exec ... {} + syntax. Mar 10, 2020 at 9:06
  • After examining closely I'm surprised: I would expect find to complain with missing argument to '-exec' and never run chmod in the first place. Oh well, maybe the implementation of find you're using is somewhat strange. Mar 11, 2020 at 8:26

1 Answer 1

0

-exec chmod 755 {} + executes the chmod command on the selected regular files in an optimized manner.

Rather than executing chmod on each individual selected file, the command line is built by appending each selected filename to the end of the command line in much the same way that xargs builds its command lines.

This means that the total number of invocations of the chmod command will typically be much less than the number of matched files.

You must log in to answer this question.

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