101-400 · Question #445
Which chown command will change the ownership to dave and the group to staff on a file named data.txt?
The correct answer is D. chown dave:staff data.txt. See the full explanation below for the reasoning.
Question
Options
- Achown dave/staff data.txt
- Bchown -u dave -g staff data.txt
- Cchown --user dave --group staff data.txt
- Dchown dave:staff data.txt
How the community answered
(29 responses)- A17% (5)
- B10% (3)
- C3% (1)
- D69% (20)
Community Discussion
6D is correct. The chown syntax for setting both owner and group in one command is user:group followed by the filename, so chown dave:staff data.txt is exactly right. The colon separator is the standard POSIX form, and none of the other options reflect actual chown syntax, chown takes no -u or --user flags and the slash separator in option A is not valid on most systems.
The slash separator in option A is actually valid on some older systems and is still accepted by GNU coreutils for backwards compatibility, so it works on Linux even if the colon form is preferred.
D is your answer. chown takes owner and group as a single argument separated by a colon, so the syntax is chown owner:group file, and you can verify that in man 1 chown under the DESCRIPTION section. Option A uses a slash which is technically accepted by some implementations for historical reasons but the colon form is what the exam expects and what POSIX documents. Options B and C do not exist as valid flags, chown has no -u or --user flags because the first positional argument already handles the owner. Quick question for you though: do you know what happens when you run chown dave: data.txt with the colon but no group name after it? That behavior is worth knowing for the exam and it trips people up.
Saw this exact syntax trip up half my team when we migrated servers, D is the one that actually works.
D is right, chown uses colon syntax: dave:staff sets owner and group together.
D is right, and A would work on some older systems but the colon syntax is the standard.