Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Get Group Names on Linux/Unix

Linux

  1. Get information of the staff group.

    $ getent group staff
    staff:x:20:
    
  2. Get group ID of the staff group.

    $ getent group staff | cut -d: -f3
    20
    

Mac

  1. Get information of the staff group.

    $ dscl . -read /Groups/staff
    
  2. Get group ID of the staff group.

    $ dscl . -read /Groups/staff | awk …