How can we get list of non-system users on linux?

You can use awk for this task:

awk -F: '$3 >= 1000' /etc/passwd

This will split the /etc/passwd file by colon, then if field 3 (userid) is greater than or equal to 1000, it will print the entire /etc/passwd record.

If you want to get only the username out of this list then:

awk -F: '$3 >= 1000 {print $1}' /etc/passwd

Where $1 is the first field of etc/passwd which is the username.


Supposing that the system recognizes only local users (i.e. those recorded in /etc/passwd, as opposed to any authenticated via a remote service such as LDAP, NIS, or Winbind), you can use grep, sed, or awk to extract the data from /etc/passwd. awk is the most flexible of those, but how about a solution with sed:

sed -n '/^\([^:]\+\):[^:]\+:[1-9][0-9]\{3\}/ { s/:.*//; p }' /etc/passwd

You need to get all users whose gid is greater than or equals 1000. Use this command for that:

awk -F: '($3>=1000)&&($1!="nobody"){print $1}' /etc/passwd

If you want system users (gid<1000) it will be:

awk -F: '($3<1000){print $1}' /etc/passwd