Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

groups

Show the names of the groups a user is in.

Level
Everyday Linux
Group
Users and groups
Needs root
No
Package
coreutils

What it does

groups prints the group names of the current process, or of the users you name. It is the same as id -Gn. The first name is the primary group.

How to write it

groups [OPTION]... [USER]...

Options 3

Most used

USER
Show the groups of this user (more names allowed).
--help
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1My groups

    groups
    student wheel

    The first is the primary group.

  2. 2Groups of other users

    groups lisa omar
    lisa : lisa webadmins
    omar : omar wheel webadmins

    With names, each line starts with the user.

  3. 3After adding a group

    usermod -aG webadmins student
    groups; groups student
    student wheel
    student : student wheel webadmins

    The shell gets the new group only after a new login.

  4. 4Check admin rights quickly

    groups | grep -qw wheel && echo "you can use sudo"

    wheel = sudo on RHEL.

  5. 5Count the groups of a user

    groups lisa | wc -w

    The output includes the name and the colon for a named user.

  6. 6Use it in a script for many users

    for u in anna bob carol; do groups "$u"; done

    Fast check after a lab.

  7. 7Compare with id

    id -Gn lisa

    Same names, no "lisa :" before them.

  8. 8Check a group for a shared folder

    groups | grep -w sales

    Needed to write in a folder owned by group sales.

  9. 9Check the groups of a service user

    groups apache
    apache : apache

    Service accounts should have as few groups as possible.

  10. 10Find members of the docker or wheel group (audit)

    getent group wheel

    groups shows per user; getent group shows per group.

Exit codes

0 :: Done. 1 :: A user does not exist.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man groups