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

Share:
9,792

Related videos on Youtube

jabi
Author by

jabi

Updated on September 18, 2022

Comments

  • jabi
    jabi over 1 year

    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

    • Terrance
      Terrance over 6 years
      Does groups <username> from a terminal work?
    • jabi
      jabi over 6 years
      yes its working :) Thank you so much :) :) :) Post it as an answer :)
    • George Udosen
      George Udosen over 6 years
      I thought OP meant all users a particular group @Terrance?
    • Terrance
      Terrance over 6 years
      @George Yes, you are correct.
    • Terrance
      Terrance over 6 years
    • George Udosen
      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
    steeldriver over 6 years
    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