How can I display all users and groups with a command?

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?

Asked By: Pandya


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.

Answered By: Pandya

Here we are going to use getent for the detailed the info

We can list the user with the following command:

getent passwd

We can list the group as follows:

getent group

To fetch detail a specific user

getent passwd lalit

Replace the lalit with your user name. Lalit will not be in every system 🙂

You can read the more into about getent here

Answered By: Lalit Mohan
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.