30

I would like to see how many users are on my system. How could I view a list of all the users on the system?

ayy lmao
  • 781

3 Answers3

32

You can get a list of all users with

getent passwd | cut -d':' -f1

This selects the first column (user name) of the system user database. In contrast to solutions parsing /etc/passwd, this will work regardless of the type of database used (traditional /etc/passwd, LDAP, etc). Note that this list includes system users as well (e.g. nobody, mail, etc.).

The exact user number can be determined as follows:

getent passwd | wc -l

A list of currently logged in users can be obtained with the users or who command:

users  # or
who
Marco
  • 33,548
  • Why not use getent passwd to get the current user list, including users found via LDAP etc.? Also, wc -l would be a far shorter way to count the lines in /etc/passwd (or the output of getent passwd, for that matter). – n.st Jan 27 '15 at 14:20
  • @n.st That's better indeed. I included the change in my answer. Thanks. – Marco Jan 27 '15 at 18:20
  • That will not necessarily list all the user's. Some user databases can be made non-enumeratable – Stéphane Chazelas Jan 28 '15 at 00:05
4

You could simply cat the /etc/passwd file or use,

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

To cut the first field of the same file, it'd list the names you're expecting. Additonally, w who and finger would help you with who all are logged in from which locations/tty and their activity details.

1

This works:

sed 's/:.*//g' /etc/passwd
DisplayName
  • 11,688