The groups command in Linux: show the groups of a user

Introduction

In Unix-like operating systems, permission management is based on the combination of users and groups. Each process, file, or device has an associated owner (user) and group that determines who can read, write, or execute. Knowing which groups a user belongs to is the first step for diagnosing access problems, adjusting privileges, and maintaining system security.

What exactly does the groups command do?

The groups command belongs to the GNU coreutils basic utilities set. Its function is to print to standard output the list of groups to which a specified user belongs, or, if no name is given, the user executing the command. The output consists of group names separated by spaces, making it easy to process with tools such as awk, sed, or cut.

Syntax and options

The simplest form is:

groups [user]

There are no long or short options that modify its behavior; the command ignores any additional argument beyond the username. If more than one name is provided, it will display the list for each on separate lines.

Everyday usage examples

  • View the groups of the current user:
  • groups
  • Check the groups of another user, for example juan:
  • groups juan
  • Obtain the list in CSV format to facilitate import into a spreadsheet:
  • groups juan | tr ' ' ','
    This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .