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

muru
  • 193,181
  • 53
  • 473
  • 722
jabi
  • 65
  • 1
  • 3
  • 9

1 Answers1

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

George Udosen
  • 35,970
  • 13
  • 99
  • 121
  • 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` – steeldriver Oct 26 '17 at 02:20