Ubuntu – How to display all users and groups with a command

command linegroupsusers

I want to display:

  1. All users and

  2. All groups

    in my system using command-line.

users and groups commands display users currently logged in, and groups a user belongs to respectively.

How to display a list of all users and all groups by command-line?

Best Answer

You can display with the help of compgen builtin command as follows:

  1. To display all users run following command:

    compgen -u
    
  2. To display all groups run following command:

    compgen -g
    

However you can also display all users by cut -d ":" -f 1 /etc/passwd.