I want to display:
All users and
All groups
in my system using command-line.
users
and groups
commands display users currently logged in, and groups a user belongs to respectively.
How to display a list of all users and all groups by command-line?
You can display with the help of
compgen
builtin command as follows:To display all users run following command:
To display all groups run following command:
However you can also display all users by
cut -d ":" -f 1 /etc/passwd
.Here we are going to use
getent
for the detailed the infoWe can list the user with the following command:
We can list the group as follows:
To fetch detail a specific user
Replace the lalit with your user name. Lalit will not be in every system :)
You can read the more into about
getent
here