2

For example: Group workers have 2 users: john and jony . What command do I have to use to list the members of group workers ?

These commands don't serve my purpose: compgen -u , compgen -g, cut -d ":" -f 1 /etc/passwd

6
  • 2
    Does groups <username> from a terminal work?
    – Terrance
    Oct 25, 2017 at 21:25
  • yes its working :) Thank you so much :) :) :) Post it as an answer :)
    – jabi
    Oct 25, 2017 at 21:28
  • I thought OP meant all users a particular group @Terrance? Oct 25, 2017 at 21:30
  • @George Yes, you are correct.
    – Terrance
    Oct 25, 2017 at 21:33
  • Related: askubuntu.com/questions/136788/…
    – Terrance
    Oct 25, 2017 at 21:33

1 Answer 1

4

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

1
  • If you know the (full) group name, then you can give it as a key to getent directly (avoiding the call to grep) e.g. getent group workers Oct 26, 2017 at 2:20

Not the answer you're looking for? Browse other questions tagged .