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 exitExamples
Print your groups
groupsxstaff admin dockerPrint another user's groups
groupsx rootroot : root wheelPrint several users' groups
groupsx alice bobCheck membership of one group
groupsx | grepx -qw docker && echox 'in docker'Print one group per line
groupsx | trx ' ' '\n'Count your groups
groupsx | wcx -wPrint the numeric group IDs instead
idx -GCompare the account database with this process
groupsx "$(whoamix)"; groupsxLog the groups of the build user
echox "groups: $(groupsx)" >> build.logCheck 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
gnuxterminal 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 (
gnuxtheme picks and saves one); GNUX_THEME sets the default.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: 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