EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux List Groups

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux List Groups

Linux List Groups

Definition of Linux List Groups

In linux, the main usage of groups is to define a set of access to given resources like read, write, or execute that is to be shared among the users in the group. A set of users are called a group. in this article, we will discuss how to use group command in linux and ways to see the groups in linux.

Linux Groups:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Below are the types of groups where a user belongs to:

  • Primary Group: This is the group that is designated to the files which are created by the user. generally, the primary group’s name is similar to the name of the creator. Unique user should be belonging to only one primary or login group.
    Secondary/supplementary Group: This secondary group allows the user in granting particular privileges to a limited users. this user also might be a member of any other or many supplementary groups.

There are many ways to figure out groups that a user belongs to.

The login user’s group is located in the file – /etc/passwd and the secondary group users are located in the /etc/group file. General way to list the groups is by listing the list of the above file by using linux commands like less, cat or grep. the other way is to use the command that is providing information about the system’s groups and users.

Below are the ways to find out either group or user’s information:

  • /etc/group File: User group file
  • Members Command: List members of a group
  • Lid Command (or Libuser-Lidon Newer Linux Distros): List user’s groups or group’s users

Syntax of Group List Command in Linux

Syntax of using groups command in linux can we done in two ways. they are:

Popular Course in this category
Kali Linux Training (3 Courses, 3+ Projects)3 Online Courses | 3 Hands-on Projects | 21+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,494 ratings)
Course Price

View Course

Related Courses
Linux Training Program (16 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

One by mentioning username associated with the group.

Groups [username]....

Second by just mentioning ‘groups’ as shown below:

$groups

How Does Linux List Groups Work?

We can get the list of groups in linux by two ways:

  • /etc/group File
  • Getent Command

These command are explained briefly using syntaxes and examples below for better
understanding. the above options are described below:

1. Using /etc/group File

To get all the local groups in the system, we can go to /etc/group file. as this is a file, we can open it and see all the local groups present.

Cat /etc/group

Linux List Groups-1.1

2. Using Getent Command

Getent command in linux will help to get the entries from databases that is stored in the name service switch libraries. with this, we can get the information of groups from group database.

Getent Group

Linux List Groups-1.2

Examples of Group List Command in Linux

Below are the ways to use group command in linux with its syntax and example.

  • We can print only the group names using cut command as show below. this example can be suited best when you are searching for any specific name of group in the system.

Command:

Cat -D: -F1 /etc/group

Example: The cut command here is spliting the line with colon(:) as its delimiter. the first field is cut by using -f1 option.

Linux List Groups-1.3

  • We can list all the group names in alphabetical order by using sort command in linux. the sort command usually helps to sort the output in alphabetical order.

Command:

Getent Group | Cut -D: -F1 | Sort

Output:

Linux List Groups-1.4

  • We can also count the number of groups present in the system using ‘-c’ option. here we can count the group names in both /etc/group file and by using getent command. syntax and example is given below.

Command:

Cat /etc/group | Grep -C ""
Getent Group | Grep -C ""

Output:

Linux List Groups-1.5

To list all the user’s groups in the system we can use groups keyword. syntax and example is given below.

Syntax:

Groups Username

Command:

Groups Admin

Output:

Linux List Groups-1.6

  • To list the groups of current user in the system, we need to run the groups command without any username. It will then print the groups that the current user is associated with.

Command:

Groups

Output:

Linux List Groups-1.7

  • To list the user groups in the system along with group id, we need to run the id command. it will then print the groups associated with its group id.

Syntax:

Id Username

Command:

Id Root

Output:

Linux List Groups-1.8

  • To list all the members in a group, we can use getent group command with the group name. syntax and example is given below.

Syntax:

Getent Group Group_Name

Command:

Getent Group Admin

Output:

Linux List Groups-1.9

Note: When you get no output for the above syntax, that means there is no such group available in the system.

Conclusion

A set of users are called a group. in linux, the main usage of groups is to define a set of access to given resources like read, write, or execute that is to be shared among the users in the group. In this article, we have seen that /etc/group file and getent command will give you the complete information on the group lists in linux. to modify the output, we have also used cut, sort, count options for better understanding.

Recommended Articles

This is a guide to Linux List Groups. Here we also discuss the definition and how does linux list groups work? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Linux comm
  2. Linux Regular Expression
  3. rmdir command in Linux
  4. Linux Alias Command

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Kali Linux Training Learn More