Linux Administration
medium
Pregunta de Linux Administration #019e3987
Enunciado de la Pregunta
Linux Administration
#chown
#file-ownership
#group-ownership
#posix-syntax
Medio
Which of the following commands changes the ownership of file.txt to the user dan and the group staff?
A
chown dan/staff file.txt
B
chown dan:staff file.txt
Correcto
C
chown -u dan -g staff file.txt
D
chown dan -g staff file.txt
Explicación Oficial / Explicaciones de la Comunidad
The chown command is used to change the owner and/or group of a file. The correct syntax to change both the owner and group simultaneously is chown owner:group file. In this case, chown dan:staff file.txt sets the owner to dan and the group to staff.
How it Works
The chown command accepts a colon (:) as a separator between the owner and group. When both are specified, the file's user and group ownership are updated accordingly. The colon is the standard POSIX syntax for this operation.
Why the Correct Value is Right
chown dan:staff file.txtuses the colon separator, which is the correct and most common way to specify both owner and group in a single command.
Why the Incorrect Values are Wrong
chown dan/staff file.txtuses a slash (/) as a separator, which is not a valid syntax forchown. The slash is not recognized and will result in an error or unexpected behavior.chown -u dan -g staff file.txtuses the-uand-gflags, but these flags do not exist in the standardchowncommand. The correct flags for specifying owner and group are not-uand-g; instead, the colon syntax is used.chown dan -g staff file.txtattempts to use a-gflag to set the group, but-gis not a valid flag forchown. Additionally, the command would be interpreted as changing the owner todanand then applying an invalid flag, leading to an error.