How to List Users in Linux

List Users in Linux

System Administrators needs to configure and manage users and groups in the system. There are different commands to Add User, Delete User etc. but to list all the users this may be a critical task. In this tutorial, you are going to learn how to list users in Linux.

List all users using /etc/passwd file.

For each user account on system /etc/passwd file contains one line. So you can easily display login information of each user using this file.

Display login information of each user using cat command.

cat passwd

The output should be similar like this:

How to list users in Linux - Cat Command
How to list users in Linux – Cat Command

In the above screenshot each line contains 7 fields delimited by colons which contain the following data:

  1. Username
  2. Encrypted password where x means password is saved in etc/shadow file.
  3. UID (User ID)
  4. GID (User’s Group ID)
  5. Full Name of User
  6. User $HOME directory
  7. Login shell path

By using awk and cut commands you can list only username’s in the file

awk -F: '{ print $1}' /etc/passwd
cut -d: -f1 /etc/passwd

The output should be similar to this:


List all users using getent command

Getent command is used to read entries from database. Getent lists users from both LDAP database and /etc/passwd file.

List all users with getent command.

getent passwd
How to List Users in Linux - Getent Command
How to List Users in Linux – Getent Command

You can also print only usernames by using cut and awk command.

getent passwd | cut -d: -f1
getent passwd | awk -F: '{ print $1}'

Checking if user exists in Linux system

You have learned to list users in Linux what if you want to check if a user exists or not. You can do so by using following commands.

There are two ways using getent command to check specific user exists or not. First is using grep command or without grep command. Assume we want to check user john exists or not, then the commands will be:

getent passwd | grep john

and without grep command.

getent passwd john

NOTE: if the user exists it will print user login info otherwise nothing will be printed.

To check the total number of users present in the system use following command.

getent passwd | wc -l

The output should be similar like this:


There are 47 users present on the system.

Differentiate System and Normal Users

When installing the Operating System or installing or updating new packages, new users are created in the system.

Normal users are the users created by root user or users created with sudo privileges. Normal users have real login shell and $HOME directory.

Each user has a UID (User ID) either he is system user or normal user. When normal user adds user by using adduser command. User will be added and UID will be assigned automatically with reference of UID_MIN and UID_MAX from file /etc/login.defs.

To check UID_MIN and UID_MAX type:

grep -E '^UID_MIN|^UID_MAX' /etc/login.defs

The output should be:

UID_MIN			 1000
UID_MAX			60000

The above output shows all normal users lied between 1000 and 60000.

Now to print all normal users between 1000 to 60000 enter following command.

getent passwd {1000..60000}

The output should be:


To print only usernames type following command

eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1

List all Groups in Linux

You can list all groups in Linux by using the following command.

getent group

And to list all groups with specific user run following command.

getent group | grep username


You have successfully learned how to List Users in Linux. If you have any queries regarding this please don’t forget to comment below.