how to list groups along with its users using terminal in ubuntu 14.04.5?
9,792
Several options are available:
getent group <group_name> | cut -d":" -f4-
or
grep -iE "^adm" /etc/group | cut -d":" -f4-
Note you have to add the group name where I have "^adm
, this will present members of that group.
See: man getent
Related videos on Youtube
Author by
jabi
Updated on September 18, 2022Comments
-
jabi over 1 year
For example: Group
workers
have 2 users:john
andjony
. What command do I have to use to list the members of groupworkers
?These commands don't serve my purpose:
compgen -u
,compgen -g
,cut -d ":" -f 1 /etc/passwd
-
Terrance over 6 yearsDoes
groups <username>
from a terminal work? -
jabi over 6 yearsyes its working :) Thank you so much :) :) :) Post it as an answer :)
-
George Udosen over 6 yearsI thought OP meant all users a particular group @Terrance?
-
Terrance over 6 years@George Yes, you are correct.
-
Terrance over 6 yearsRelated: askubuntu.com/questions/136788/…
-
George Udosen over 6 years@jabi in addition to Terrance link this could be helpful too
grep -iE "^adm" /etc/group | cut -d":" -f4-
-
-
steeldriver over 6 yearsIf you know the (full) group name, then you can give it as a key to
getent
directly (avoiding the call togrep
) e.g.getent group workers