21

In order to change both a file's owner and group we can do this:

chown trump file
chgrp trump file

but can I do both commands in one approach or one command?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
yael
  • 12,598
  • 51
  • 169
  • 303

1 Answers1

35

per chown man page chown user:group file:

chown trump:trump file
sebasth
  • 14,332
  • 4
  • 50
  • 68
  • 5
    Or `chown trump: file` if `trump` is the primary group of user `trump` – xhienne Aug 03 '17 at 15:52
  • 1
    Or `chown user.group filename` or `chown .group filename` – ivanivan Aug 03 '17 at 17:11
  • 5
    POSIX specifies allowed characters for user and group names. (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278) The BSD `chown` manual states "Previous versions of the chown utility used the dot (`.`) character to distinguish the group name. This has been changed to be a colon (`:`) character, so that user and group names may contain the dot character." The RHEL man page for `chown` does not have that usage note. Nonetheless, there are reasons to abstain from using the `.` character. – Christopher Aug 03 '17 at 17:31
  • 3
    Be careful what `username:` and `:groupname` are **not** standards - see https://unix.stackexchange.com/a/136989/383045 – Manuel Jordan Sep 22 '21 at 01:51