groups Command in Linux



groups command in Linux is used to display the group memberships of a user. The groups on the other hand are collections of users that help you in managing permission and accessing files and resources.

When you run the groups command followed by a username, it shows primary and any supplementary groups that the users belong to. If no username is provided, it displays the groups for the current user.

The groups command is pretty useful for system administrators in case they want to quickly check and manage user group memberships.

Table of Contents

Here is a comprehensive guide to the options available with the groups command in linux −

Syntax for groups Command

The syntax for the groups command in Linux is quite straightforward, here it is −

groups [options] [username]

Where,

  • [options] are flags that can be used with the command.
  • [username] is the name of the user whose group memberships you want to display. If no username is provided, the command will display the group memberships of the current user.

groups Command Options

The groups command doesnt have any special flags that can be used to change the commands behavior. You can only use options like --help or --version to view information about the command or its version.

Examples of groups Command in Linux

Lets explore a few practical examples of groups command in Linux system −

  • Displaying Group Memberships of the Current User
  • Displaying Group Memberships of a Specific User
  • Displaying Group Memberships for the Root User
  • Getting Help Information
  • Getting Version Information

Display Group Memberships of the Current User

To view the group memberships of the current user, you can simply use the groups command without any options or username. Doing this will help you see which groups the current user belongs to.

groups
Group Memberships of Current User groups Command

Displaying Group Memberships of a Specific User

If you need to check the group memberships of a specific user, you can provide the username as an argument to the groups command. This is useful for system administrators to verify user group memberships.

groups username
Group Memberships of Specific User groups Command

Displaying Group Memberships for the Root User

To display the group memberships for the root user, you can specify root as the username with the command. This is useful for checking the groups that the root user belongs to.

groups root
Group Memberships of Root User groups Command

Getting Help Information

To get help information about the groups command, you can use the --help option. This provides a brief description of the command and its options.

groups --help
Getting Help Information groups Command

Getting Version Information

To display the version of the groups command, you can use the --version option. This is helpful to know which version of the command is installed in your system.

groups --version
Getting Version Information groups Command

Conclusion

The groups command in Linux is a simple yet powerful tool for displaying user group memberships. It helps users manage permissions and access control efficiently by providing quick insights into which groups a user belongs to.

In this tutorial, we have explored the syntax, options and a few practical examples of the groups command. Whether you are checking your own group memberships or those of other users, this command is an essential part of Linux user management.

Advertisements