How to find list of users in Linux

In this article, we will see how to find list of users in Linux. We can find the list of users by querying against /etc/passwd file.

1. Find the list of users in Linux.

cat /etc/passwd less /etc/passwd more /etc/passwd


2. Get the list of all users including system users in Linux

cut -d: -f1 /etc/passwd

or

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

3. Find the list of all users excluding system-users in Linux .

awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd

4. Find the list of all users who can login into Linux.

Following query doesn’t show expired logins and the logins which are created but password not set.

awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow

5. Find the list of users in Linux excluding guest users from the output

cat /etc/passwd | grep -vE '(/bin/false|/sbin/nologin|/bin/sync|guest-)' | cut -d: -f1