Linux Administration
medium

Questão de Linux Administration #019e3987

Enunciado da Questão
Linux Administration
#chown
#file-ownership
#group-ownership
#posix-syntax
Médio

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

Correta
C

chown -u dan -g staff file.txt

D

chown dan -g staff file.txt

Explicação Oficial / Explicações da Comunidade

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.txt uses 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.txt uses a slash (/) as a separator, which is not a valid syntax for chown. The slash is not recognized and will result in an error or unexpected behavior.
  • chown -u dan -g staff file.txt uses the -u and -g flags, but these flags do not exist in the standard chown command. The correct flags for specifying owner and group are not -u and -g; instead, the colon syntax is used.
  • chown dan -g staff file.txt attempts to use a -g flag to set the group, but -g is not a valid flag for chown. Additionally, the command would be interpreted as changing the owner to dan and then applying an invalid flag, leading to an error.