Skip to Content
gnux

groupsx

Print the groups a user is in.

Mirrors GNU groups. Run it as groupsx, or as gnux groupsx.

Synopsis

groupsx [OPTION]... [USERNAME]...

GNU reference

Description

groupsx prints the names of the groups the current process is in: its real group, its effective group when that differs, then its supplementary groups, each once, as idx -Gn does. For each USERNAME it prints 'USERNAME : ' and the groups the account database lists for that user instead, which can differ from a running process's groups until the user logs in again. An unknown user is reported as 'no such user' and the remaining names are still printed; a group with no name is reported and printed as its number. On Windows the groups are the account's local groups, which is what Go's account lookup reports.

gnux's terminal view (BR-13): on a terminal, each user's primary group is in the theme's color for what is yours, and a USER operand in the heading color. The text is GNU's. --pretty[=WHEN] and --theme=NAME, options of gnux's own, choose the view (GNUX_PRETTY, GNUX_THEME); piped or redirected output is always GNU's.

Permissions

Needs no permissions. Reads the process's credentials and the account database.

Use cases

  • Checking that you are in the docker, wheel or sudo group after adding yourself.
  • Seeing which groups another user belongs to.
  • Debugging a 'Permission denied' on a group-writable file.
  • Recording the CI user's groups in a build log.
  • Testing group membership in a script with grepx -w.

Flags

      --help                     display this help and exit
      --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
      --theme NAME               color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
      --version                  output version information and exit

Examples

groupsx
Output
staff admin docker
groupsx root
Output
root : root wheel
groupsx alice bob

Check membership of one group

groupsx | grepx -qw docker && echox 'in docker'
groupsx | trx ' ' '\n'

Count your groups

groupsx | wcx -w
idx -G

Compare the account database with this process

groupsx "$(whoamix)"; groupsx

Log the groups of the build user

echox "groups: $(groupsx)" >> build.log

Check a group in the portable gnux shell

gnux shell -c 'if groupsx | grepx -qw wheel; then echox admin; fi'

Options

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

  • --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.
  • --theme: Color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default.

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

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

See also

On this page