Skip to Content
gnux

chgrpx

Change group ownership.

Mirrors GNU chgrp. Run it as chgrpx, or as gnux chgrpx.

Synopsis

chgrpx [OPTION]... GROUP FILE...

GNU reference

Description

chgrpx changes the group of each FILE to GROUP, a group name or numeric ID. An empty GROUP changes nothing but still checks that each FILE exists. --reference=RFILE takes the group from RFILE instead, and then every operand is a FILE. --from=CURRENT_OWNER:CURRENT_GROUP changes only the files whose current owner and group match; either part may be omitted, as in --from=alice or --from=:staff. A symbolic link given as a FILE is followed, and its referent changed, unless -h is given; when both -h and --dereference are given, -h wins. -R changes directory trees, following no symbolic link by default (-P); -H follows the ones given on the command line and -L every one, and when several are given the most cautious wins (-P, then -H, then -L). -c reports each change, -v every file, and -f suppresses most error messages. Unlike GNU chgrp, which leaves the safeguard off unless --preserve-root is given, chgrpx refuses to work recursively on '/' unless --no-preserve-root is given; when both are given, --preserve-root wins. On Windows, which has no Unix groups, every change fails with 'Operation not supported'. On a terminal, gnux's terminal view colors the -v report: the verb (removed, created, renamed), each quoted name and the arrows, in the theme --theme or GNUX_THEME names; the words are GNU's, and piped or redirected output is never colored (--pretty=never or GNUX_PRETTY=never turns it off).

Permissions

The owner of a file may change its group to any group they belong to; any other change requires root (or CAP_CHOWN). Search permission is needed on the directories leading to each FILE, and with -R read and search permission on every directory in the tree.

Use cases

  • Sharing a project directory with a team's group.
  • Giving a web server's group read access to a site with -R.
  • Fixing group ownership after extracting an archive.
  • Copying the group of one file onto others with --reference.
  • Moving only the files still in an old group to a new one with --from.
  • Checking which files would change with -c on a test run.

Flags

  -c, --changes                            like verbose but report only when a change is made
      --dereference                        affect the referent of each symbolic link (this is the default), rather than the symbolic link itself
  -L, --dereference-all                    with -R, traverse every symbolic link to a directory encountered
  -H, --dereference-args                   with -R, follow symbolic links to directories given on the command line
      --from CURRENT_OWNER:CURRENT_GROUP   change the group of each file only if its current owner and/or group match those specified here; either may be omitted (CURRENT_OWNER:CURRENT_GROUP)
      --help                               display this help and exit
  -h, --no-dereference                     affect symbolic links instead of any referenced file
      --no-preserve-root                   do not treat '/' specially
  -P, --physical                           with -R, do not traverse any symbolic links (default)
      --preserve-root                      fail to operate recursively on '/' (the default)
      --pretty WHEN[="always"]             the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
      --quiet                              same as --silent
  -R, --recursive                          operate on files and directories recursively
      --reference RFILE                    use RFILE's group rather than specifying a GROUP value
  -f, --silent                             suppress most error messages
      --theme NAME                         color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
  -v, --verbose                            output a diagnostic for every file processed
      --version                            output version information and exit

Examples

Change the group of a file

chgrpx staff report.txt

Use a numeric group ID

chgrpx 1001 report.txt

Change a whole directory tree

chgrpx -R developers project/
chgrpx -R -L developers project/
chgrpx -h staff link

Copy the group of another file

chgrpx --reference=template.conf new.conf

Move only the files still in the old team's group

chgrpx -R --from=:oldteam newteam shared/

Report only the files that changed

chgrpx -c -R staff shared/

Report every file processed

chgrpx -v staff a.txt b.txt

Suppress most error messages

chgrpx -f staff maybe-missing.txt

Give a web server's group the site files

sudo chgrpx -R www-data /var/www/site

Change groups in the portable gnux shell

gnux shell -c 'chgrpx -R staff shared && lsx -l shared'

Options

Each option has a page of its own, with its usage and examples.

  • -c, --changes: Like verbose but report only when a change is made.
  • --dereference: Affect the referent of each symbolic link (this is the default), rather than the symbolic link itself.
  • -L, --dereference-all: With -R, traverse every symbolic link to a directory encountered.
  • -H, --dereference-args: With -R, follow symbolic links to directories given on the command line.
  • --from: Change the group of each file only if its current owner and/or group match those specified here; either may be omitted (CURRENT_OWNER:CURRENT_GROUP).
  • -h, --no-dereference: Affect symbolic links instead of any referenced file.
  • --no-preserve-root: Do not treat '/' specially.
  • -P, --physical: With -R, do not traverse any symbolic links (default).
  • --preserve-root: Fail to operate recursively on '/' (the default).
  • --pretty: The gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default.
  • --quiet: Same as --silent.
  • -R, --recursive: Operate on files and directories recursively.
  • --reference: Use RFILE's group rather than specifying a GROUP value.
  • -f, --silent: Suppress most error messages.
  • --theme: Color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default.
  • -v, --verbose: Output a diagnostic for every file processed.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

chgrpx --help                # options, first examples, exit status
gnux help chgrpx             # this page: the full manual
gnux help chgrpx --OPTION    # one option in depth, with its examples

See also

On this page