Preserve shared's ordinary permissions and add SGID for group inheritance.
Which command is appropriate?
chmod g+s DIR adds SGID to a directory so new entries inherit its owning group.
Detailed explanation
chmod u+s sharedIncorrect. u+s sets SUID.
Incorrect. u+s sets SUID.
chmod g+x sharedIncorrect. g+x adds ordinary group execute/search permission only.
Incorrect. g+x adds ordinary group execute/search permission only.
chmod o+t sharedIncorrect. o+t sets sticky bit.
Incorrect. o+t sets sticky bit.
chmod g+s sharedCorrect. chmod g+s shared adds the directory SGID bit.
Correct. chmod g+s shared adds the directory SGID bit.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); chmod 775 "$tmp"; chmod g+s "$tmp"; stat -c '%A %a' "$tmp"; chmod 700 "$tmp"; rmdir "$tmp"Expected result
drwxrwsr-x 2775Key points
- g+s
- The group execute position becomes s
- Directory group inheritance
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.