idx
Print real and effective user and group IDs.
Mirrors GNU id. Run it as idx, or as gnux idx.
Synopsis
idx [OPTION]... [USER]...GNU reference
Description
idx prints the user and group IDs of the current process, or of each USER (a name or a numeric ID), in GNU's default format: 'uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo)', with euid= and egid= added when they differ from the real IDs. -u, -g and -G print only the effective user ID, the effective group ID or every group ID; -n prints names instead of numbers and -r the real IDs instead of the effective ones, with one of those three; -z ends each entry with NUL. -a is accepted and ignored, as in GNU. -Z (SELinux context) is not supported and fails, as GNU id does on a kernel without SELinux. An unknown USER is reported ('no such user') and the remaining USERs are still printed. On Windows the IDs are security identifiers (SIDs) and the names come from the account database.
gnux's terminal view (BR-13): on a terminal, the default format is a panel titled with the user's name: one labeled line an ID and its name, the effective IDs only when they differ from the real ones, and each group on a line of its own, the primary group in the theme's color for what is yours. -u, -g and -G are 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; names are read from the system's user and group databases.
Use cases
- Checking which user and groups a script or service runs as.
- Getting the numeric UID and GID to pass to
chownxor a container. - Checking whether a user belongs to a group, such as docker or sudo.
- Refusing to run a script as root by testing
idx -u. - Listing a user's groups by name.
Flags
-a, --all ignore, for compatibility with other versions
-Z, --context print only the security context of the process (not supported)
-g, --group print only the effective group ID
-G, --groups print all group IDs
--help display this help and exit
-n, --name print a name instead of a number, for -u,-g,-G
--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
-r, --real print the real ID instead of the effective ID, with -u,-g,-G
--theme NAME color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
-u, --user print only the effective user ID
--version output version information and exit
-z, --zero delimit entries with NUL characters, not whitespace; not permitted in default formatExamples
Print your user and group IDs
idxPrint another user's IDs
idx alicePrint only the effective user ID
idx -uPrint your user name
idx -unPrint the effective group ID
idx -gList your groups by name
idx -GnPrint the real user ID rather than the effective one
idx -ruRefuse to run as root
[ "$(idx -u)" -eq 0 ] && { echox 'do not run as root' >&2; exit 1; }Check membership of a group
idx -Gn | trx ' ' '\n' | grep -qx docker && echox memberPass your IDs to a container
docker run --user "$(idx -u):$(idx -g)" imagePrint IDs in the portable gnux shell
gnux shell -c 'idx -un && idx -Gn'Options
Each option has a page of its own, with its usage and examples.
- -a, --all: Ignore, for compatibility with other versions.
- -Z, --context: Print only the security context of the process (not supported).
- -g, --group: Print only the effective group ID.
- -G, --groups: Print all group IDs.
- -n, --name: Print a name instead of a number, for
-u,-g,-G. - --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. - -r, --real: Print the real ID instead of the effective ID, with
-u,-g,-G. - --theme: Color the view with the built-in theme NAME (
gnuxtheme picks and saves one); GNUX_THEME sets the default. - -u, --user: Print only the effective user ID.
- -z, --zero: Delimit entries with NUL characters, not whitespace; not permitted in default format.
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
idx --help # options, first examples, exit status
gnux help idx # this page: the full manual
gnux help idx --OPTION # one option in depth, with its examples