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?

  • 2
    i think /etc/passwd would help you. Jan 27 '15 at 10:59
  • 5
    Do you mean how many user accounts are on the system, or how many users are currently logged in?
    – D_Bye
    Jan 27 '15 at 11:00

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
  • 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 Jan 28 '15 at 0:05

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.


This works:

sed 's/:.*//g' /etc/passwd
  • You could also remove the global flag if you want to. Jan 27 '15 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.