Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Bash exec + chmod incomprehensive argument

Writer Sebastian Wright

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

1 Answer

-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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy