Keep script.sh's existing permissions and add execute permission for its owner.
Which command is appropriate?
chmod u+x adds the execute bit to the owner class without replacing the other permission bits.
Detailed explanation
chmod 644 script.shIncorrect. chmod 644 sets read/write permissions and does not add execute.
Incorrect. chmod 644 sets read/write permissions and does not add execute.
chmod u+x script.shCorrect. u+x adds owner execute permission while preserving existing modes.
Correct. u+x adds owner execute permission while preserving existing modes.
chown +x script.shIncorrect. chown changes ownership, not permission bits.
Incorrect. chown changes ownership, not permission bits.
exec script.shIncorrect. exec runs a command and does not change file permissions.
Incorrect. exec runs a command and does not change file permissions.
Try it yourself
An example you can run in a temporary verification environment.
script=$(mktemp); chmod 600 "$script"; chmod u+x "$script"; stat -c '%A' "$script"; rm -f -- "$script"Expected result
所有者欄にxを含む-rwx------Key points
- u means owner
- + adds
- x means execute
Notes
- Environment: GNU coreutils 9.x / 一時ファイル
- 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.