2

I'm fresh to Linux , to be precise this is the first day I'm sitting before Ubuntu OS. I added users for a learning purpose & now I want to see all the users in the system. How do I see the users ? If there is more than 1 way, kindly let me know all.

2 Answers 2

2

Failsafe way

They are listed in /etc/passwd. However, this will include "system" users. Generally, "normal" users start with a UID of 1000, so you can filter these out with.

awk -F ':' '$3>999' /etc/passwd

N.B. that I also have a user called "nobody" with UID 65534, so there are some false positives.

Explanation of code

  • awk -F ':' use awk with field seperator of :.
  • '$3>999' only print line if the third field is greater than 999.
  • /etc/passwd read from this file.

Easier way

Most users will have a directory in home. N.B. this may not work if a user doesn't have this directory.

ls /home

(Also, ignore lost+found if it exists, as it's not associated with a user.)

1
  • Both are excellent, however please be aware that the two methods can give different results, because UIDs and GIDs used for home folders can differ from those specified in the /etc/passwd file, e.g. by sharing the same UID across some users home folders (or even all in case of NFS).
    – mirekphd
    Sep 4 at 12:17
0

getent passwd

This method has the advantage of listing both users that are defined on this system (i.e. listed in /etc/passwd) and users that may be brought in via a single sign-on method, e.g. LDAP users.

If you only want to see the non-system users:

getent passwd | awk -F ':' '$3>999' | grep -v nobody

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .