Find regular *.conf files under current and pass as many results as possible together to chmod g-w.
Which command is appropriate?
find -exec command {} + appends multiple matching paths to each command invocation. Using \; normally runs one invocation per result.
Detailed explanation
find current -type f -name '*.conf' -exec chmod g-wIncorrect. The -exec expression is incomplete without a terminator.
Incorrect. The -exec expression is incomplete without a terminator.
find current -type f -name '*.conf' -exec chmod g-w {} \;Incorrect. \; terminates -exec but usually invokes chmod once per file.
Incorrect. \; terminates -exec but usually invokes chmod once per file.
find current -type f -name '*.conf' -exec {} chmod g-w +Incorrect. The command and placeholder are in the wrong order.
Incorrect. The command and placeholder are in the wrong order.
find current -type f -name '*.conf' -exec chmod g-w {} +Correct. -exec chmod g-w {} + batches matching paths.
Correct. -exec chmod g-w {} + batches matching paths.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/a.conf" "$tmp/b.conf"; chmod 660 "$tmp/a.conf" "$tmp/b.conf"; find "$tmp" -type f -name '*.conf' -exec chmod g-w {} +; stat -c '%a' "$tmp/a.conf" "$tmp/b.conf"; rm -rf "$tmp"Expected result
640
640Key points
- {} is replaced by results
- + batches results
- \; runs one at a time
Notes
- Environment: GNU findutils 4.x / GNU chmod / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.