22

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?

1
  • 1
    Why the downvotes?
    – kevin
    Commented Aug 21, 2017 at 8:01

1 Answer 1

36

per chown man page chown user:group file:

chown trump:trump file
4
  • 5
    Or chown trump: file if trump is the primary group of user trump
    – xhienne
    Commented Aug 3, 2017 at 15:52
  • 1
    Or chown user.group filename or chown .group filename
    – ivanivan
    Commented Aug 3, 2017 at 17:11
  • 5
    POSIX specifies allowed characters for user and group names. (pubs.opengroup.org/onlinepubs/9699919799/basedefs/…) 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. Commented Aug 3, 2017 at 17:31
  • 3
    Be careful what username: and :groupname are not standards - see unix.stackexchange.com/a/136989/383045 Commented Sep 22, 2021 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .