- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find what group a given user has on Linux?
We know that we can print all the users that are present on Linux with the help of the Linux utility command known as compgen.
The compgen command is a Linux utility command that is used to list all the commands that can be executed in a Linux terminal, and when used with a -u flag we can simply print all the users present on Linux.
Consider the command shown below as reference −
compgen -u
Output
root daemon bin sys sync games man lp mail news uucp proxy www-data backup . . .
Now if we want to print the total groups that are present on our Linux operating system, we can either make use of the groups command.
The groups command is used to print all the groups that are present on the Linux kernel.
Syntax
groups [options]
Usually the options in the above command are replaced by a particular user, for whom we want to check how many groups are present.
Let’s consider a few examples of the group's command.
Command
groups
Output
sh-3.2# groups wheel daemon kmem sys tty operator procview procmod everyone staff certusers localaccounts admin com.apple.sharepoint.group.1 _appstore _lpadmin _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh com.apple.access_remote_ae
If you want to check groups of a particular user then run the below command.
Command
groups immukul
Output
sh-3.2# groups immukul staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin com.apple.sharepoint.group.1 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh com.apple.access_remote_ae